D:MongoDBServer3.4in>mongo MongoDB shell version v3.4.16-41-g83c3022fe4 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.16-41-g83c3022fe4 Server has startup warnings: 2019-09-04T11:06:41.286+0800 I CONTROL [initandlisten] 2019-09-04T11:06:41.286+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled fo r the database. 2019-09-04T11:06:41.286+0800 I CONTROL [initandlisten] ** Read and write access to data an d configuration is unrestricted. 2019-09-04T11:06:41.286+0800 I CONTROL [initandlisten] 2019-09-04T11:06:41.286+0800 I CONTROL [initandlisten] Hotfix KB2731284 or later update is not inst alled, will zero-out data files. 2019-09-04T11:06:41.286+0800 I CONTROL [initandlisten] > show dbs admin 0.000GB local 0.000GB test 0.000GB > use students switched to db students > db.class.insert({'name':'吴唐华'}) WriteResult({ "nInserted" : 1 }) > show collections class > db.class.drop() true > db.class2.insert({'name':'cwl','age':45,'sex':1}) WriteResult({ "nInserted" : 1 }) > db.class2.insert({'name':'yt','age':26,'sex':0}) WriteResult({ "nInserted" : 1 }) > db.class2.insert({'name':'jn','age':26,'sex':0}) WriteResult({ "nInserted" : 1 }) > db.class2.find() { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 45, "sex" : 1 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26, "sex" : 0 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26, "sex" : 0 } > db.class2.updata({'age':45},{$set:{'age':2}}) 2019-09-04T14:47:23.195+0800 E QUERY [thread1] TypeError: db.class2.updata is not a function : @(shell):1:1 > db.class2.update({'age':45},{$set:{'age':2}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.class2.find() { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 2, "sex" : 1 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26, "sex" : 0 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26, "sex" : 0 } > db.col.find({"name":{$type:2}}) > db.class2.find({"name":{$type:2}}) { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 2, "sex" : 1 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26, "sex" : 0 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26, "sex" : 0 } > > db.class.find()pretty() 2019-09-04T15:17:22.253+0800 E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1 :15 > db.class.pretty() 2019-09-04T15:17:30.826+0800 E QUERY [thread1] TypeError: db.class.pretty is not a function : @(shell):1:1 > db.class2.update({'age':{$gt:22},{$set:{'sex':2}}) ... db.class2.find({"name":{$type:2}}) ... ... db.class2.update({'age':4},{$set:{'age':1}}) > db.class2.update({'age':45},{$set:{'age':3}}) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 }) > db.class2.update({'age':2},{$set:{'age':3}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.class2.update({'age':{$gt:3}},{$set:{'sex':3}},true,true) WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 }) > db.class2.find() { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 3, "sex" : 1 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26, "sex" : 3 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26, "sex" : 3 } > db.class2.find().pretty() { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 3, "sex" : 1 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26, "sex" : 3 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26, "sex" : 3 } > db.class2.update({'name':'lys'},{$set:{'age':12,"sex":'yes'}},true,true) WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : ObjectId("5d6f69b56685a146689b9147") }) > db.class2.find() { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 3, "sex" : 1 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26, "sex" : 3 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26, "sex" : 3 } { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : 12, "sex" : "yes" } > db.class2.update({'name':'lys'},{$set:{'age':12,"sex":'yes'}},true,true) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 }) > db.class2.find() { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 3, "sex" : 1 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26, "sex" : 3 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26, "sex" : 3 } { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : 12, "sex" : "yes" } > db.class2.update({'name':'lys'},{$set:{'age':12,"sex":'yes'}},true,true).find() 2019-09-04T15:40:22.078+0800 E QUERY [thread1] TypeError: db.class2.update(...).find is not a fun ction : @(shell):1:1 > db.class2.find(db.class2.update({'name':'lys'},{$set:{'age':12,"sex":'yes'}},true,true)) Error: error: { "ok" : 0, "errmsg" : "cannot compare to undefined", "code" : 2, "codeName" : "BadValue" } > db.class2.find({'name':'lys'},{$set:{'age':12,"sex":'yes'}},true,true).find() 2019-09-04T15:44:16.304+0800 E QUERY [thread1] TypeError: db.class2.find(...).find is not a funct ion : @(shell):1:1 > db.class2.find(db.class2.update({'name':'lys'},{$set:{'age':12,"sex":'yes'}},true,true)) Error: error: { "ok" : 0, "errmsg" : "cannot compare to undefined", "code" : 2, "codeName" : "BadValue" } > db.class2.find({'name':'lys'},{$set:{'age':12,"sex":'yes'}},true,true) Error: error: { "ok" : 0, "errmsg" : ">1 field in obj: { age: 12.0, sex: "yes" }", "code" : 2, "codeName" : "BadValue" } > db.class2.find({'name':'mgq'},{$set:{'age':12,"sex":'yes'}},true,true) Error: error: { "ok" : 0, "errmsg" : ">1 field in obj: { age: 12.0, sex: "yes" }", "code" : 2, "codeName" : "BadValue" } > db.class2.find() { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 3, "sex" : 1 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26, "sex" : 3 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26, "sex" : 3 } { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : 12, "sex" : "yes" } > db.class2.find({'name':'lys'},{$set:{'age':12,"sex":'yes'}},true,true) Error: error: { "ok" : 0, "errmsg" : ">1 field in obj: { age: 12.0, sex: "yes" }", "code" : 2, "codeName" : "BadValue" } > db.class2.find({'by':'lys'}) > db.class2.find({'by':'lys'}) > db.class2.find({'by':'lys'}).pretty() > db.class2.insert({'name':'yt','class':'0506','age':26,'money':10000}) WriteResult({ "nInserted" : 1 }) > db.class2.insert({'name':'clw','class':'0506','age':24,'money':20000}) WriteResult({ "nInserted" : 1 }) > db.class2.insert({'name':'szy','class':'0325','age':24,'money':20000000}) WriteResult({ "nInserted" : 1 }) > db.class2.insert({'name':'szy','class':'0325','age':24,'money':20}) WriteResult({ "nInserted" : 1 }) > db.class.find({$or:[{'class':'0325'},{'class':'0506'}]}) > db.class.find({$or:[{'class':'0325'},{'class':'0506'}]}) > db.class2.find({$or:[{'class':'0325'},{'class':'0506'}]}) { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "name" : "yt", "class" : "0506", "age" : 26, "money" : 10000 } { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "name" : "clw", "class" : "0506", "age" : 24, "money " : 20000 } { "_id" : ObjectId("5d6f73f69b7e3e911a123a88"), "name" : "szy", "class" : "0325", "age" : 24, "money " : 20000000 } { "_id" : ObjectId("5d6f73ff9b7e3e911a123a89"), "name" : "szy", "class" : "0325", "age" : 24, "money " : 20 } > db.class2.insert({'name':'lm','class':'1224','age':24,'money':200000000000}) WriteResult({ "nInserted" : 1 }) > db.class.find({'money':{$gte:2000},$or:[{'class':0325},{'class':'0506'}]}).pretty() > db.class2.find({'money':{$gte:2000},$or:[{'class':0325},{'class':'0506'}]}).pretty() { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "name" : "yt", "class" : "0506", "age" : 26, "money" : 10000 } { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "name" : "clw", "class" : "0506", "age" : 24, "money" : 20000 } > db.class2.find({'money':{$gte:2000},$or:[{'class':0325},{'class':'0506'}]},{'_id':0,'class':0).pre tty() ... ... db.class.find({'money':{$gte:2000},$or:[{'class':0325},{'class':'0506'}]},{'class':1}).pretty() ... ... > > > db.class2.find({'money':{$gte:2000},$or:[{'class':0325},{'class':'0506'}]},{'class':1}).pretty() { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "class" : "0506" } { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "class" : "0506" } > db.class2.find({},{'mame':1}).limit(2) { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83") } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84") } > db.class2.find({},{'name':1}).limit(2) { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl" } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt" } > db.class2.find({},{'name':1,'age':1}).sort({'age':-1}) { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26 } { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "name" : "yt", "age" : 26 } { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "name" : "clw", "age" : 24 } { "_id" : ObjectId("5d6f73f69b7e3e911a123a88"), "name" : "szy", "age" : 24 } { "_id" : ObjectId("5d6f73ff9b7e3e911a123a89"), "name" : "szy", "age" : 24 } { "_id" : ObjectId("5d6f75509b7e3e911a123a8a"), "name" : "lm", "age" : 24 } { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : 12 } { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 3 } > db.class2.find({},{'name':1,'age':1}).sort({'age':1}) { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : 3 } { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : 12 } { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "name" : "clw", "age" : 24 } { "_id" : ObjectId("5d6f73f69b7e3e911a123a88"), "name" : "szy", "age" : 24 } { "_id" : ObjectId("5d6f73ff9b7e3e911a123a89"), "name" : "szy", "age" : 24 } { "_id" : ObjectId("5d6f75509b7e3e911a123a8a"), "name" : "lm", "age" : 24 } { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : 26 } { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : 26 } { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "name" : "yt", "age" : 26 } > db.class2.count() 9 > db.class2.aggregate([{$group:{_id:'class',num:{$max:'money'}}}]) { "_id" : "class", "num" : "money" } > db.class2.aggregate([{$group:{_id:'class',num:{$max:'money'}}}]) { "_id" : "class", "num" : "money" } > db.class2.aggregate([{$group:{_id:'class',num:{$max:'money'}}}]) { "_id" : "class", "num" : "money" } > db.class2.aggregate([{$group:{'_id':'class',num:{$max:'money'}}}]) { "_id" : "class", "num" : "money" } > db.class2.aggregate([{$group:{_id:'class',num:{$max:'$money'}}}]) { "_id" : "class", "num" : 200000000000 }