"MongoDB:" A slightly more complex operation

Source: Internet
Author: User

1: Inserting data in slightly complex form

Doc= ({"user_id": "Abcdbwn",  "password": "Abcdbwn",  "Date_of_join":  "15/10/2010",  "education": "B. C.A. ",  " profession ":" DEVELOPER ",  " interest ":" Music ",  " Community_Name ": [" Modern MUSIC ",                                    " Classicalmusic ",                    " WESTERN MUSIC "],  " community_moder_id ": [" Mr BBB ",                                           " Mr Jjj ","          mrmmm "],  " Community_members ": [+                                           ],"  friends_id ": [" MMM123 ",                       " NNN123 ",       " OOO123 "],  "ban_friends_id": ["BAN123",                              "BAN456",                              "BAN789"]});

> Db.person.insert (DOC) Writeresult ({"ninserted": 1})

2: Use the For loop to insert the document in bulk, as the previous blog has said.

3: Conditional Query

' > ' corresponds to ' $gt ',

' < ' corresponds to ' $lt ',

' >= ' corresponds to ' $gte '

' <= ' corresponds to ' $lte ',

'! = ' corresponds to ' $ne ',

' = ' corresponds to ' no keyword '

Example: Querying the uid>98 data

> Db.person.find ({"UID": {$gt: 98}}) {"_id": ObjectId ("55471dfc994c2a0fdbfa128b"), "UID": +, "addr": "Shanghai" } {"_id": ObjectId ("55471dfc994c2a0fdbfa128c"), "UID": "addr": "Shanghai"}>

For example, the query UID does not equal 99 of the amount of data

> Db.person.find ({"UID": {$ne: ()}). Count () 100

And $in, $nin, etc.

Example: Querying uid=100 and addr= documents for "Shanghai"

> Db.person.find ({"UID": +, "addr": "Shanghai"}) {"_id": ObjectId ("55471dfc994c2a0fdbfa128b"), "UID": +, "addr": "Shanghai"}>

Querying uid=100 or addr= "Shanghia" documents

Db.person.find ({$or: [{},{}]})

> Db.person.find ({$or: [{"UID": 100},{"addr": "Shanghai"}]}). Count ()

  

Query addr documents that begin with S:

> Db.person.find ({"addr":/^s/})

  

Query the document ending with addr one I:

> Db.person.find ({"addr":/i$/})

  

Querying with a Where condition

> Db.person.find ({$where: function () {return this.uid==88}}) {"_id": ObjectId ("55471dfc994c2a0fdbfa1297"), "UID": "Addr": "Shanghai"}>

  

"MongoDB:" A slightly more complex operation

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.