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