Show DBS;
User MONGO_DWZ;
Show collections;
Db.member.find (); var document = ({no: "xxxxx0002", Name: "hwj002", age:24, url: "http://blog.csdn.net/huweijun_2012/article/details/5186
5569 ", Password:" 8090987998d ", Phone:" 13027981420 ", sex:0, Status:1, Address:" Shenzhen Baoan District Central Avenue 1000th "});
Db.member.insert (document); Db.member.update ({no: "xxxxx0002", Name: "hwj002"},{$set: {name: "New name", age:32}},{upsert:false,//upsert: optional, this
The parameter means that if there is no record of update, insert Objnew,true is inserted, default is False, do not insert.
Multi:true//multi: Optional, mongodb default is False, only update the first record found, if this parameter is true, will be found on the condition of a number of records update all.
});
Db.member.find (). pretty ();
The Save () method replaces an existing document with an incoming document Db.member.save ({_id:objectid ("56064f89ade2f21f36b03136"), No: "xxxxx0002", Name: "Hwj002", age:90, url: "http://blog.csdn.net/huweijun_2012/article/details/51865569", Password: "8090987998d", Phone: "
13027981420 ", Sex:1, Status:1, Address:" Shenzhen Baoan District Central Avenue, No. 1000th "});
The pretty () method displays all documents in a formatted manner.
Db.member.find (). pretty (); The basic syntax format for the Remove () method is as follows: DB.MEMBER.REmove ({no: "xxxxx0002"});
Delete all data Db.member.remove ({});
Query document Db.member.find ({no: "xxxxx0002", $or: [{no: "xxxxx0002"},{name: "xxxxx0002"}]}). Pretty (); $gt > $gte >= $lt < $lte <= $ne <> $or or $set $in in $nin [not in] Db.member.find ({age:{$gte: $lte: $, sex:1, $or: [{no: "xxxxx0 002 "},{name:" xxxxx0002 "}], phone:{$ne: ' 13027981840 '}, url:{$in: [" Url1 "," Url1 "," URL1 "]}, url:{$nin: [" url_00 "," Url_
99 "]}); SELECT * from member where age>= and Age<=30 and Sex=1 and (no= ' xxxxx0002 ' or name = ' xxxxx0002 ') and phone &L
T;> ' 13027981840 ';
Db.member.find ({$or: [{url:{$in: ["Url1", "Url1", "URL1"]},},{sex:1}]);
The $mod divides the value of the query by the first value, and returns the result Db.member.find ({age:{$mod: [5,1]}}) if the remainder equals the second given value;
Users such as 1,6,11,16 are returned.
If you want to return users who are not 1,6,11,16 these.: Db.member.find ({age:{$not: {$mod: [5,1]}}});
Null does not only match itself, but also matches the non-existent.
The following are: query name is null and exists. Db.member.find ({
name:{$in: [null], $exists: true}});
Regular Db.member.find ({url:/www.////^www.$/});
Paging Db.member.find (). Limit (1). Skip (2). Pretty ();
Sort//-1 desc (Descending), 1 asc (Ascending) Db.member.find (). Limit (). Skip (). Sort ({age:-1}). Pretty ();
$slice returns a subset of the array var blog = ({id:1222, title: ' About China development ', Author: ' Weijunhu ', date:122222222222, comments:[ {name: ' Joerr ', emial: ' 57@cc.omc ', content: ' Nice document ', Score:3}
{name: ' Boorss ', emial: ' 8957@cc.omc ', content: ' Nice document, go ', score:6
}]
});
Db.blog.find ({id:1222}, {comments:{$slice:-1}});
The result is: var res = {id:1222, title: ' About China development ', Author: ' Weijunhu ', date:122222222222, comments:[{
Name: ' Boorss ', emial: ' 8957@cc.omc ', content: ' Nice document, go ', score:6}]};
$elemMatch//Groups The qualifying conditions, which are only used when multiple key operations are required on an inline document. Db.blog.find ({comments:{$eLemmatch:{name: "Joerr", scor:{$gte: 3}}});
MongoDB uses the Ensureindex () method to create an index. Db.
The KEY value in Collection_name.ensureindex ({key:1})//syntax is the index field you want to create, 1 for the specified index in ascending order, or 1 if you want to create an index in descending order.
Db.blog.ensureIndex ({title:1});
Inline Document Index Db.blog.ensureIndex ({"Comments.name": 1});
Custom index name Db.blog.ensureIndex ({a:1,b:-1},{name: "Alphabet"});
Unique index Db.member.ensureIndex ({no:1},{unique:true});
Composite unique index//See if Index Db.member.find ({userName: "NO698989"}) is used. Explain ();