MongoDB comes with a JavaScript Shell, so it is possible to use the JS syntax in it.
Insert operation:
Single Insert
var single={"name":"mei"," Age ":}db.user.insert (single);
Loop insert
var single={"name":"tinyphp","num ":",} for(var i=0;i<5; i++) { Single.num=i;db.user.insert (single);}
Find query operation:
Commonly used for:
>=, <, <=,! =, =
> Corresponding $GT
>= corresponding $gte
< corresponding $LT
<= corresponding $lte
! = corresponds to $ne
= = Direct write value such as Db.user.find ({"Age": 22})
/* Find Age >22 */ Db.user.find ({"Age":$})
&&
/* find Name= "tinyphp" && num=3 */ Db.user.find ({"name":"tinyphp"," Num ":3})
Or
/* find Name= "tinyphp" | | num=3 */ Db.user.find ({$or: [{"name":"tinyphp"},{" num":3}]})
Inch
/* find name in ["Tinyphp", "Jack"] */ Db.user.find ({"name": {$in: ["tinyphp" ,"Jack"]})
Not in
/* find name not in ["tinyphp", "Jack"] */ Db.user.find ({"name": {$nin: ["tinyphp"," Jack"]})
Regular match
/* the Find name starts with the J */ Db.user.find ({"name":/^j/})
$where Query
Db.user.find ({$where: function () {returnthis. name=='jack'} })
Update operation:
Overall update
var model=db.user.findone ({"name":"Jack"}) Model.age=db.user.update ({"name":" Jack"},model)
Local updates
$inc modifiers
/**/db.user.update ({"name":"Bing "},{$inc: {"Age":+})
$set modifiers
/** /db.user.update ({"name":"Bing "},{$set: {"Age":Ten}})
True parameter for update
If the last parameter of update is true then the modification condition does not exist, automatically adding one such as:
Db.user.update ({"name":"Mark"},{$set: {" Age":Ten}},true)
will automatically add a record: Name Mark,age is 10
If true is added and the condition is met, it will be modified in bulk, or only the first one will be updated by default.
Remove Operation:
Db.person.remove ({"name":"Jack"})
MongoDB additions and deletions