mongo命令

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" ] }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值