Apsaradb for mongodb basic exercise records

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.