Apsaradb for mongodb basic exercise records
Apsaradb for mongodb basic exercise records
Db. getCollection ('foo'). find (). pretty ();
Db. getCollection ('foo'). findOne ();
Db. getCollection ('foo'). find ({"hello": "world "});
Db. getCollection ('foo'). find ({"hello": {$ ne: "world "}});
// $ Lt; <
Db. getCollection ('user _ test '). find ({"age": {$ lt: "28"}); // the query set is user_test, with the condition that the age is less than 28
// $ Lte; <=
Db. getCollection ('user _ test '). find ({"age": {$ lt: "28"}); // query records whose age is less than or equal to 28 with the set user_test
// $ Gt;>
Db. getCollection ('user _ test '). find ({"age": {$ gt: "28"}); // the query set is user_test, with the condition that the record is older than 28
// $ Gte;> =
Db. getCollection ('user _ test '). find ({"age": {$ gte: "28"}); // the query set is user_test, and the condition is that the record whose age is greater than or equal to 28
// $ Ne ;! =
Db. getCollection ('user _ test '). find ({"age": {$ ne: "28"}); // query records with the user_test set and age not equal to 28
Db. getCollection ("foo"). find ({"hello": "world", "hello": "world "});
Select * from foo where hello = "world" AND hello = "world ";
Db. getCollection ("foo"). find ({$ or: [{"hello": "world" },{ "hello": "world2"}]});
Db. getCollection ("foo"). find ({"hello": "world", $ or: [{"hello": "world"}]});
// Mysql like
Db. getCollection ("foo"). find ({"hello": {$ regex: "world2 "}});
Db. getCollection ("fooo"). find ({"hello":/world2 /});
Db. getCollection ("foo"). find ({"hello":/^ (world) | (world2) $/I });
Db. getCollection ("user_test "). find (). sort ({"name":-1 }). skip (0 ). limit (10); // the query set is user_test, the sorting key is name, And the sorting method is-1 in reverse order, skip (0 ). limit (10) from 0 to 10
// Insert record
Db. user_test.insert ({name: 'zhang san ',
??? Age: '18 ',
??? Sex: 'male ',
??? Favorite: ['mongodb ', 'database', 'nosql'],
}) // Insert a set of user_test
Db. user_test.insert ({name: 'zhang san ',
??? Age: '18 ',
??? Sex: 'male ',
??? Favorite: {"sports": {"ball": "basketball", "games": "fire"}, "books": {"animal": "animal World ", "cars": "Auto World "}},
})
Db. user_test.insert ({name: 'zhang san ',
??? Age: '18 ',
??? Sex: 'male ',
??? Favorite: {"sports": {"ball": "basketball", "games": "fire"}, "books": {"animal": "animal World ", "cars": "Auto World "}},
})
Db. user_test.insert ({name: 'zhang san ',
??? Age: '18 ',
??? Sex: 'male ',
??? Favorite: {"sports": {"ball": "basketball", "games": "fire"}, "books": {"animal": "animal World ", "cars": "Auto World "}},
})
Db. user_test.insert ({name: 'zhang san ',
??? Age: '18 ',
??? Sex: 'male ',
??? Favorite: {"sports": "running, playing ing "},
})
Db. user_test.update ({"name": "Zhang San"}, {$ set: {"favorite. sports. ball ":" footerball "}); // modify a favorite whose name is zhangsan. sports. the ball value is footerball.
Db. user_test.update ({"name": "Zhang San"}, {$ set: {"favorite. sports. ball ":" footerball "}}, {multi: true}); // modify all favorite whose names are John. sports. the ball value is footerball.
Db. user_test.remove ({"name": "zhangsan"}); // delete all records whose names are zhangsan
Db. user_test.remove ({"name": "Zhang San"}, 1); // delete a record whose name is Zhang San. When the second parameter of remove is 1, delete one record.