db.version() current version of the server
> use shop
switched to db shop
> show collections;
> db.createCollection("user")
{ "ok" : 1 }
> show collections;
user
> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
shop 0.000GB
> db.user.insert({name:'lisi',age:22})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
> db.user.insert({name:'lisi',age:23})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
> db.user.insert({name:'lisi',age:23,address:'wangtang'})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
> db.user.insert({name:'lisi',age:23,address:'wangtang1'})
WriteResult({ "nInserted" : 1 })
> db.user.insert({name:'lisi',age:23,address:'wangtang2'})
WriteResult({ "nInserted" : 1 })
> db.user.insert({name:'lisi',age:23,address:'wangtang3'})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
> db.user.insert({name:'lisi',age:24,address:'wangtang3'})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : ObjectId("5a9a89adc345d61fef7c8831"), "name" : "lisi", "age" : 24, "address" : "wangtang3" }
> db.user.insert({name:'lisi',age:23,address:'wangtang3',_id:1})
WriteResult({ "nInserted" : 1 })
> db.user.insert({name:'lisi',age:23,address:'wangtang3',_id:2})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : ObjectId("5a9a89adc345d61fef7c8831"), "name" : "lisi", "age" : 24, "address" : "wangtang3" }
{ "_id" : 1, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : 2, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
> db.user.insert({name:'lisi',age:23,address:'wangtang3',_id:2,hobby:["basketball","football"]})
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 11000,
"errmsg" : "E11000 duplicate key error collection: shop.user index: _id_ dup key: { : 2.0 }"
}
})
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : ObjectId("5a9a89adc345d61fef7c8831"), "name" : "lisi", "age" : 24, "address" : "wangtang3" }
{ "_id" : 1, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : 2, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
> db.user.insert({name:'lisi',age:23,address:'wangtang3',_id:3,hobby:["basketball","football"]})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : ObjectId("5a9a89adc345d61fef7c8831"), "name" : "lisi", "age" : 24, "address" : "wangtang3" }
{ "_id" : 1, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : 2, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : 3, "name" : "lisi", "age" : 23, "address" : "wangtang3", "hobby" : [ "basketball", "football" ] }
>
> use shop
switched to db shop
> show collections;
> db.createCollection("user")
{ "ok" : 1 }
> show collections;
user
> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
shop 0.000GB
> db.user.insert({name:'lisi',age:22})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
> db.user.insert({name:'lisi',age:23})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
> db.user.insert({name:'lisi',age:23,address:'wangtang'})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
> db.user.insert({name:'lisi',age:23,address:'wangtang1'})
WriteResult({ "nInserted" : 1 })
> db.user.insert({name:'lisi',age:23,address:'wangtang2'})
WriteResult({ "nInserted" : 1 })
> db.user.insert({name:'lisi',age:23,address:'wangtang3'})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
> db.user.insert({name:'lisi',age:24,address:'wangtang3'})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : ObjectId("5a9a89adc345d61fef7c8831"), "name" : "lisi", "age" : 24, "address" : "wangtang3" }
> db.user.insert({name:'lisi',age:23,address:'wangtang3',_id:1})
WriteResult({ "nInserted" : 1 })
> db.user.insert({name:'lisi',age:23,address:'wangtang3',_id:2})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : ObjectId("5a9a89adc345d61fef7c8831"), "name" : "lisi", "age" : 24, "address" : "wangtang3" }
{ "_id" : 1, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : 2, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
> db.user.insert({name:'lisi',age:23,address:'wangtang3',_id:2,hobby:["basketball","football"]})
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 11000,
"errmsg" : "E11000 duplicate key error collection: shop.user index: _id_ dup key: { : 2.0 }"
}
})
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : ObjectId("5a9a89adc345d61fef7c8831"), "name" : "lisi", "age" : 24, "address" : "wangtang3" }
{ "_id" : 1, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : 2, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
> db.user.insert({name:'lisi',age:23,address:'wangtang3',_id:3,hobby:["basketball","football"]})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5a9a8911c345d61fef7c882b"), "name" : "lisi", "age" : 22 }
{ "_id" : ObjectId("5a9a8962c345d61fef7c882c"), "name" : "lisi", "age" : 23 }
{ "_id" : ObjectId("5a9a8980c345d61fef7c882d"), "name" : "lisi", "age" : 23, "address" : "wangtang" }
{ "_id" : ObjectId("5a9a8992c345d61fef7c882e"), "name" : "lisi", "age" : 23, "address" : "wangtang1" }
{ "_id" : ObjectId("5a9a8996c345d61fef7c882f"), "name" : "lisi", "age" : 23, "address" : "wangtang2" }
{ "_id" : ObjectId("5a9a8999c345d61fef7c8830"), "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : ObjectId("5a9a89adc345d61fef7c8831"), "name" : "lisi", "age" : 24, "address" : "wangtang3" }
{ "_id" : 1, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : 2, "name" : "lisi", "age" : 23, "address" : "wangtang3" }
{ "_id" : 3, "name" : "lisi", "age" : 23, "address" : "wangtang3", "hobby" : [ "basketball", "football" ] }
>