mongodb常规操作语句
1 db.c_user.insertOne({ 2 name: "ljm", 3 pwd: "123456" 4 }); //插入一个 5 6 db.c_user.insertMany([{ 7 item: "wjl", 8 age: "25", 9 tags: ["blank", "red"], 10 size: { 11 h: 14, 12 w: 21 13 } 14 }, 15 { 16 item: "ljm", 17 age: "18", 18 tags: ["blank", "red"], 19 size: { 20 h: 14, 21 w: 21 22 } 23 }]) ;//插入多个 24 db.c_type.insertMany([{ 25 item: "wjl", 26 age: "25", 27 tags: ["blank", "red"], 28 size: { 29 h: 14, 30 w: 21 31 } 32 }, 33 { 34 item: "ljm", 35 age: "18", 36 tags: ["blank", "red"], 37 size: { 38 h: 14, 39 w: 21 40 } 41 }]) ;//插入多个 42 43 db.getCollection("c_user").find({}) ; 44 db.getCollection("c_user").find(); 45 db.c_user.find({ 46 name: "ljm" 47 }) ;//Key:value 查询,相当于where name = "" 48 49 db.getCollection("c_type").find({}); 50 51 db.c_user.find({ 52 name: "wjl", 53 age: { 54 $lt: 30 55 } 56 }); // where .. and ... ,lt < ; gt > 57 58 db.c_user.find({ 59 $or: [{ 60 name: "wjl" 61 }, 62 { 63 age: { 64 $lt: 30 65 } 66 }] 67 }); // where ... or ... 68 69 db.c_user.find({ 70 name: "wjl", 71 $or: [{ 72 age: { 73 $lt: 30 74 } 75 }, 76 { 77 name: /^m/ 78 }] 79 }); // where and .. or .. 80 81 db.c_user.find({ 82 name: { 83 $in: ["wjl", "ljm"] 84 } 85 }) ;//where in 86 db.c_user.updateOne({ 87 "_id": ObjectId("5d034c0de20035e8e98d684a") 88 }, 89 { 90 $set: { 91 pwd: "1315565452", 92 name: "zhangsan" 93 } 94 }); //修改一个 95 96 db.c_user.updateMany({ 97 name: "wjl" 98 }, 99 { 100 $set: { 101 pwd: "1315565452", 102 name: "zhangsan" 103 } 104 }); //修改多个 105 106 db.c_user.replaceOne({ 107 name: "ljm" 108 }, 109 { 110 name: "ljm", 111 age: "80" 112 }) ;//替换一个 113 114 db.c_user.deleteOne({ 115 "_id": ObjectId("5d034fdee20035e8e98d6850") 116 }) ;//删除一个
欢迎评论留言交流