1. Insert the ********************************use tblorders;--method 1db.tblorders.insert ({ OrderNo: "A2014089901", PName: "Tblorders", Scity: "Beijing"});d B.tblorders.insert ({orderno: "A2014089902", PName: "SN Ow ", scity:" Chengdu "});d B.tblorders.insert ({orderno:" A2014089903 ", PName:" Kiki ", Scity:" Chongqing "});d B.tblorders.find ();--method 2db.tblorders.save ({orderno: "A2014089904", PName: "Atalas", Scity: "Urumqi", Sdate: "2015-08-08"});--Method 3for (var i = 1; I &l t;= 300; i++) Db.tblorders.save ({id:i, Name: ' Ocpyang '}); ********************************2. Update ***************************** ---method: Set updates all Ocpyang to Atalasdb.tblorders.update ({name: "Ocpyang"}, {$set: {name: "Atalas"}},false,true);---method: $ Inc$inc usage: {$inc: {field:value}} meaning to a Number field field add Value, Example: Db.tblorders.insert ({orderno: "10001", PName: "Ocpyang", s City: "Chongqing", price:1500});d B.tblorders.find ({"PName": "Ocpyang"}). ForEach (Printjson); {"_id": ObjectId ("55BF126B4726E2D2DC5F43CD"), "OrderNo": "10001", "PName": "OCPyang "," scity ":" Chongqing "," Price ": 1500}db.tblorders.update ({" OrderNo ":" 10001 "}, {$inc: {' price ': ']}});d B.tblor Ders.find ({"PName": "Ocpyang"}). ForEach (Printjson); {"_id": ObjectId ("55BF126B4726E2D2DC5F43CD"), "OrderNo": "10001", "pname": "Ocpyang", "scity": "Chongqing", "Price": 1630}**** 3. Delete ******************************** $unset usage: {$unset: {field:1}}--1. A row db.tblorders.update ({"id": 1}, {$unset: {"Naje": 1}}) satisfying the condition,--2. All rows that satisfy the condition Db.tblorders.update ({"Name": "Atalas"}, { $unset: {"name": 1}},false,true); ********************************4. Query ******************************** Db.tblorders.insert ({orderno: "10001", PName: "Ocpyang", Scity: "Chongqing", price:1500});d B.tblorders.insert ({orderno: "100 ", PName:" Luces ", scity:" Tianjin ", price:1280});d B.tblorders.insert ({orderno:" 10010 ", PName:" Andy Lau ", Scity:" Shanghai Pudong ", Ecity: "Houston", price:9850});--Method 1db.tblorders.find ();--Method 2db.tblorders.find ({"PName": "Kiki"});--Method 3db.tblorders.find ({" PName ":" Kiki "}). Limit (1);--Method 4db.tblorders.find ({"PName": "Kiki"}). foreach (Printjson);d b.tblorders.find ({"PName": "Andy Lau"}). foreach ( Printjson);--Method 5: Greater than, equal to, less than, less than or equal to, Betweendb.tblorders.find ({"Price": {$gt: ()}). ForEach (Printjson); Db.tblorders.find ({"Price": {$gte:). foreach (Printjson);d the B.tblorders.find ({"Price": {$lt:}}). foreach ( Printjson);d b.tblorders.find ({"Price": {$lte: ()). ForEach (Printjson);--greater than 1700 less than 10000db.tblorders.find ({" Price ": {$gt: 1700, $lt: 10000}}). foreach (Printjson);--Method 6: Not equal to Db.tblorders.find ({" Price ": {$ne: 1630}}). foreach ( Printjson); eg: greater than 1300 less than 10000 is not equal to 1630db.tblorders.find ({"Price": {$ne: 1630, $GT: 1300, $LT: 10000}}). ForEach (Printjson );--Method 7:indb.tblorders.find ({"Price": {$gt: +}}). ForEach (Printjson); {"_id": ObjectId ("55BF126B4726E2D2DC5F43CD"), "OrderNo": "10001", "pname": "Ocpyang", "scity": "Chongqing", "Price": 1630} {"_id": ObjectId ("55bf15bd4726e2d2dc5f43ce"), "OrderNo": "10001", "pname": "Ocpyang", "scity": "Chongqing", "Price": 1500} {"_id": ObjectId ("55BF15BD4726E2D2DC5F43CF"), "OrderNo": "10005", "pname": "Luces", "scity": "Tianjin", "Price": 1280}{"_id": ObjectId ("55bf15be4726e2d2dc5f43d0"), " OrderNo ":" 10010 "," PName ":" Andy Lau "," scity ":" Shanghai Pudong "," ecity ":" Houston "," Price ": 9850}db.tblorders.find ({" Price ": {$in: [12 80,1500]}). ForEach (Printjson); {"_id": ObjectId ("55bf15bd4726e2d2dc5f43ce"), "OrderNo": "10001", "pname": "Ocpyang", "scity": "Chongqing", "Price": 1500} {"_id": ObjectId ("55BF15BD4726E2D2DC5F43CF"), "OrderNo": "10005", "pname": "Luces", "scity": "Tianjin", "Price": 1280}--Method 8: Not Indb.tblorders.find ({' price ': {$nin: [1280,1500], $GT: +}}). ForEach (Printjson); {"_id": ObjectId ("55BF126B4726E2D2DC5F43CD"), "OrderNo": "10001", "pname": "Ocpyang", "scity": "Chongqing", "Price": 1630} {"_id": ObjectId ("55bf15be4726e2d2dc5f43d0"), "OrderNo": "10010", "PName": "Andy Lau", "scity": "Shanghai Pudong", "ecity": "Houston", " Price ": 9850}--method 9:skip limit the return record's starting point Db.tblorders.find (). Skip (2). Limit (5); #从第3条开始返回5条-Method 10:sort sort Db.tblorders.find ({"Price": {$gt: 0}}). The sort ({price:1}). ForEach (Printjson);d B.Tblorders.find ({"Price": {$gt: 0}}). sort ({price:1});d B.tblorders.find ({' price ': {$gt: 0}}). Sort ({price:-1});--method 11: Cursor for (var c = db.tblorders.find ({"Price": {$gt: 0}}), C.hasnext ();) {Printjson (C.next ());} Db.tblorders.find ({"Price": {$gt: 0}}). ForEach (function (u) {printjson (U);}); 5. Statistics ********************************db.tblorders.find (). Count ();
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MongoDB additions and deletions to search