> db.user02.find({age:{$gt:5}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find({age:{$lt:4}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
> db.user02.find({age:{$gte:2}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find({age:{$lte:3}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
> db.user02.find({age:{$ne:2}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find({age:2})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
> db.user02.find({age:{$mod:[2,0]}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
> db.user02.find({age:{$mod:[2,1]}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.count()
10
> db.user01.count()
1
> db.user03.count()
1
> db.user02.find()
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find().count()
10
> db.user02.find({age:{$gt:5}}).count()
4
> db.user02.find().skip(2).limit(3)
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
> db.user02.sort({age:-1})
2018-08-02T15:35:34.354+0800 TypeError: Property 'sort' of object dbtest.user02 is not a function
> db.user02.find().sort({age:-1})
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
> db.user02.find()
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find().sort({age:-1})
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
> db.user02.find().sort({age:-1}).skip(3).limit(3)
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
> db.user02.find().sort({age:-1}).skip(3).limit(3).count()
10
> db.user02.find().sort({age:-1}).skip(3).limit(3).count(0)
10
> db.user02.find().sort({age:-1}).skip(3).limit(3).count(1)
3
> db.user02.find({age:{$all:[135]}})
> db.user02.find({age:{$all:[1,3,5]}})
> db.user02.find({age:{$all:[1,5]}})
> db.user02.find()
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find({age:{$all:[2,9]}})
> db.user02.find({age:{$all:[1,2]}})
> db.user02.find({age:{$all:[1]}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
> db.user02.find({age:{$all:[1,3,5]}})
> db.user02.find({age:{$in:[1,3,5]}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
> db.user02.find({age:{$nin:[1,3,5]}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find({age:{$nin:[1,3,12]}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find({age:{$or:[1,3,12]}})
error: {
"$err" : "Can't canonicalize query: BadValue unknown operator: $or",
"code" : 17287
}
> db.user02.find({$or:[name:"haha02"],{age:4}})
2018-08-02T15:44:25.129+0800 SyntaxError: Unexpected token :
> db.user02.find({$or:[{name,"haha02"},{age,4}])
...
... }
2018-08-02T15:45:23.554+0800 SyntaxError: Unexpected token ,
> db.user02.find({$or:[{name,"haha02"},{age,4}]})
2018-08-02T15:45:30.428+0800 SyntaxError: Unexpected token ,
> db.user02.find({$or:[{name:"haha01"},{age:2}]})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
> db.user02.find({$or:[{name:"haha01"},{age:3}]})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
> db.user02.find({$or:[{name:"haha4"},{age:3}]})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
> db.user02.find({$nor:[{name:"haha4"},{age:3}]})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find({age:{$exists:1}})
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user02.find({age:{$exists:0}})
> db.user02.find({age:{$exists:0}})
> show dbs
admin (empty)
dbtest 0.078GB
local 0.078GB
> db
dbtest
> show tables
system.indexes
user01
user02
user03
> db.user01.find()
{ "_id" : ObjectId("5b62b0ae86a5a8512ef0398b"), "name" : "xiaoming", "age" : 20 }
> db.user02.find()
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "haha6", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "haha7", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "haha8", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "haha9", "age" : 9 }
> db.user03.find()
{ "_id" : ObjectId("5b62b08986a5a8512ef0398a"), "name" : "jack" }
> db.createCollection("user04")
{ "ok" : 1 }
> show tables
system.indexes
user01
user02
user03
user04
> db.user04.insert({name:123})
WriteResult({ "nInserted" : 1 })
> db.user04.find()
{ "_id" : ObjectId("5b62b9ea86a5a8512ef03996"), "name" : 123 }
> db.user04.drop()
true
> show tables
system.indexes
user01
user02
user03
> show tables
system.indexes
user01
user02
user03
> db
dbtest
> show dbs
admin (empty)
dbtest 0.078GB
local 0.078GB
> db.createCollection("db01")
{ "ok" : 1 }
> show dbs
admin (empty)
dbtest 0.078GB
local 0.078GB
> show talbes
2018-08-02T16:01:52.043+0800 don't know how to show [talbes] at src/mongo/shell/utils.js:729
> show tables
db01
system.indexes
user01
user02
user03
> db.getName()
dbtest
> show dbs
admin (empty)
dbtest 0.078GB
local 0.078GB
> db.getName()
dbtest
> show dbs
admin (empty)
dbtest 0.078GB
local 0.078GB
> use db82
switched to db db82
> db
db82
> show tables
> db.createCollection("user01")
{ "ok" : 1 }
> show tables
system.indexes
user01
> db.user02.insert({age:2})
WriteResult({ "nInserted" : 1 })
> show tables
system.indexes
user01
user02
> db.user02.find()
{ "_id" : ObjectId("5b62bb0686a5a8512ef03997"), "age" : 2 }
> db.user01.find()
> show tables
system.indexes
user01
user02
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
> db
db82
> db.getName()
db82
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
> db.createCollection("test01")
{ "ok" : 1 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
> use test01
switched to db test01
> db
test01
> show tables
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 (empty)
> db
test01
> db.createCollection("mongo01")
{ "ok" : 1 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> show tables
mongo01
system.indexes
> show tables
mongo01
system.indexes
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> db.getName()
test01
> show db
2018-08-02T16:08:52.863+0800 don't know how to show [db] at src/mongo/shell/utils.js:729
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> use test02
switched to db test02
> show tables
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
test02 (empty)
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
test02 (empty)
> show tables
> db.dropDatabase()
{ "dropped" : "test02", "ok" : 1 }
> db
test02
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> db
test02
> db.createCollection("collection01")
{ "ok" : 1 }
> show tables
collection01
system.indexes
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
test02 0.078GB
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
test02 0.078GB
> db.dropDatabase()
{ "dropped" : "test02", "ok" : 1 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> sb
2018-08-02T16:11:18.468+0800 ReferenceError: sb is not defined
> db
test02
> db.test01.drop()
false
> db.test01.drop()
false
> show tables
> db.dropDatabase(test01)
2018-08-02T16:12:30.148+0800 ReferenceError: test01 is not defined
> db.dropDatabase("test01")
2018-08-02T16:12:40.227+0800 dropDatabase doesn't take arguments at src/mongo/shell/db.js:141
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
test02 (empty)
> show tables
> show tables
> db
test02
> show tables
> db.createCollection("collection01")
{ "ok" : 1 }
> show tables
collection01
system.indexes
> db.createCollection("collection02")
{ "ok" : 1 }
> show tables
collection01
collection02
system.indexes
> db.collection01.drop()
true
> show tables
collection02
system.indexes
> show tables
collection02
system.indexes
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
test02 0.078GB
> db.dropDatabase()
{ "dropped" : "test02", "ok" : 1 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> show tables
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
test02 (empty)
> db.dropDatabase()
{ "dropped" : "test02", "ok" : 1 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> show collections
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
test02 (empty)
> db.dropDatabase()
{ "dropped" : "test02", "ok" : 1 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> use test01
switched to db test01
> show tables
mongo01
system.indexes
> show collections
mongo01
system.indexes
> show tables
mongo01
system.indexes
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> show collections
mongo01
system.indexes
> db.createCollection("collection01")
{ "ok" : 1 }
> show tables
collection01
mongo01
system.indexes
> show collections
collection01
mongo01
system.indexes
> db.createCollection("collection02")
{ "ok" : 1 }
> show tables
collection01
collection02
mongo01
system.indexes
> db.createCollection("zzz01")
{ "ok" : 1 }
> show collections
collection01
collection02
mongo01
system.indexes
zzz01
> show tables
collection01
collection02
mongo01
system.indexes
zzz01
> db.zzz01.insert(name:"124")
2018-08-02T16:18:34.371+0800 SyntaxError: Unexpected token :
> db.zzz01.insert({name:"123"})
WriteResult({ "nInserted" : 1 })
> show collections
collection01
collection02
mongo01
system.indexes
zzz01
> show tablse
2018-08-02T16:19:03.642+0800 don't know how to show [tablse] at src/mongo/shell/utils.js:729
> show tables
collection01
collection02
mongo01
system.indexes
zzz01
> db.zzz01.find()
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
> for(var i = 1 ; i<10 ; i++){
... db.zzz01.insert({age:i+i})
... }
WriteResult({ "nInserted" : 1 })
> show tables
collection01
collection02
mongo01
system.indexes
zzz01
> show collections
collection01
collection02
mongo01
system.indexes
zzz01
> db.zzz01.find()
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> show collections
collection01
collection02
mongo01
system.indexes
zzz01
> db.zzz01.find()
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find({age:2})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
> db.zzz01.findOne()
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
> db.zzz01.findOne()
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
> db.zzz01.find({},{age:2})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998") }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find({},{name:1})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999") }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a") }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b") }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c") }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d") }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e") }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f") }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0") }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1") }
> db.zzz01.find({},{name:0})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998") }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> show tables
collection01
collection02
mongo01
system.indexes
zzz01
> show collections
collection01
collection02
mongo01
system.indexes
zzz01
> db.zzz01.find()
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> show dbs
admin (empty)
db82 0.078GB
dbtest 0.078GB
local 0.078GB
test01 0.078GB
> show tables
collection01
collection02
mongo01
system.indexes
zzz01
> db.zzz01.find()
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find({age:{$lt:4}})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
> db.zzz01.find({age:{$lt:9}})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
> db.zzz01.find({age:{$gt:4}})
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find()
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find({age:{$lte:6}})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
> db.zzz01.find({age:{$gte:6}})
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find({age:{$ne:6}})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find({age:{$mod:[2,0]}})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find({age:{$mod:[2,1]}})
> db.zzz01.count()
10
> db.zzz01.find().count()()
10
> db.zzz01.find().count(1)
10
> db.zzz01.find().sort({key:1})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find().sort({key:-1})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find().sort({key:-1})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find().sort({age:-1})
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
> db.zzz01.find().sort({age:1})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find().sort({age:1}).skip(3).limit(3)
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
> db.zzz01.find().sort({age:1}).skip(3).limit(3)
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
> db.zzz01.find({age:{$all:[1]}})
> db.zzz01.find({age:{$all:[2]}})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
> db.zzz01.find({age:{$all:[2,4]}})
> db.zzz01.find({age:{$in:[2,4]}})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
> db.zzz01.find({age:{$nin:[2,4]}})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find($or:[{age:2},{age:4}])
2018-08-02T16:30:45.724+0800 SyntaxError: Unexpected token :
> db.zzz01.find({$or:[{age:2},{age:4}]})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
> db.zzz01.find({$or:[{age:2},{age:3}]})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
> db.zzz01.find({$and:[{age:2},{age:3}]})
> db.zzz01.find({$and:[{age:2},{age:4}]})
> db.zzz01.find({age:{$exists:1}})
{ "_id" : ObjectId("5b62bef186a5a8512ef03999"), "age" : 2 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399a"), "age" : 4 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399b"), "age" : 6 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399c"), "age" : 8 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399d"), "age" : 10 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399e"), "age" : 12 }
{ "_id" : ObjectId("5b62bef186a5a8512ef0399f"), "age" : 14 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a0"), "age" : 16 }
{ "_id" : ObjectId("5b62bef186a5a8512ef039a1"), "age" : 18 }
> db.zzz01.find({age:{$exists:0}})
{ "_id" : ObjectId("5b62be6b86a5a8512ef03998"), "name" : "123" }
>
> db.user02.update({age:{$gte:6}},{$set:{name:"aa"}},0,1)
WriteResult({ "nMatched" : 4, "nUpserted" : 0, "nModified" : 4 })
> db.user02.find()
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "aa", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "aa", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "aa", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "aa", "age" : 9 }
> db.user02.update({age:6},{name:"bb"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.user02.find()
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "bb" }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "aa", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "aa", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "aa", "age" : 9 }
> db.user02.update({name:"bb"},{$set:{name:"bb"},{age:6}})
2018-08-02T21:51:33.423+0800 SyntaxError: Unexpected token {
> db.user02.update({name:"bb"},{$set:{age:6}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.user02.find()
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "bb", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "aa", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "aa", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "aa", "age" : 9 }
> db.user02.update({age:6},{$set:{name:"cc"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.user02.find()
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398c"), "name" : "haha0", "age" : 0 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398d"), "name" : "haha1", "age" : 1 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398e"), "name" : "haha2", "age" : 2 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef0398f"), "name" : "haha3", "age" : 3 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03990"), "name" : "haha4", "age" : 4 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03991"), "name" : "haha5", "age" : 5 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03992"), "name" : "cc", "age" : 6 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03993"), "name" : "aa", "age" : 7 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03994"), "name" : "aa", "age" : 8 }
{ "_id" : ObjectId("5b62b10d86a5a8512ef03995"), "name" : "aa", "age" : 9 }
>
远远看去优美而神秘的人和事,只要拉近了看,就会明白它们原来既不神秘又不优美。
——马塞尔·普鲁斯特《追忆似水年华》