use DATABASE_NAME
> use myFirstDBswitched to db myFirstDB> db.myFirstDB.insert({"test":"myFirstDB"})WriteResult({ "nInserted" : 1 })
> show dbsadmin 0.000GBconfig 0.000GBlocal 0.041GBmyFirstDB 0.000GB
db.createCollection(name, options)
options 字段 | 类型 | 描述 |
capped | BOOL | 指是否设置集合的最大字节数。如果为 true,需设置 size 参数。默认为 false。 |
autoIndexId | BOOL | 设置是否自动创建索引。如为 true,自动在 _id 字段创建索引。默认为 false。 |
size | 数值 | 设置集合的最大字节数。 |
max | 数值 | 设置集合包含文档的最大数量。 |
> use myFirstDBswitched to db myFirstDB> db.createCollection("FirstCol"){"ok" : 1,"$clusterTime" : {"clusterTime" : Timestamp(1634821900, 2),"signature" : {"hash" : BinData(0,"WFu7yj8wjeUBWG3b+oT84Q8wIw8="),"keyId" : NumberLong("6990600483068968961")}},"operationTime" : Timestamp(1634821900, 2)}
> show collectionsFirstCol
> db.createCollection("FirstCol", { capped : true, autoIndexId : true, size : 6142800, max : 10000 } ){"note" : "the autoIndexId option is deprecated and will be removed in a future release","ok" : 1,"$clusterTime" : {"clusterTime" : Timestamp(1634821879, 1),"signature" : {"hash" : BinData(0,"EuIbp2fu9Yh38HOBHLgYqljdKaE="),"keyId" : NumberLong("6990600483068968961")}},"operationTime" : Timestamp(1634821879, 1)}
> db.FirstCol.insert({name:"黎四",sex:"女",age:25,status:"A"})WriteResult({ "nInserted" : 1 })
> db.FirstCol.find(){ "_id" : ObjectId("61716957a6fe1ef4d7eae979"), "name" : "黎四", "sex" : "女", "age" : 25, "status" : "A" }
db.collection.insertMany([ <document 1> , <document 2>, ... ])
> db.FirstCol.insertMany([{name:"黎三",sex:"女",age:25,status:"A"},{name:"王六",sex:"男",age:26,status:"B"},{name:"王五",sex:"男",age:26,status:"A",groups:["news","sports"]}]){"acknowledged" : true,"insertedIds" : [ObjectId("617282a3a4bb72d733b5c6d7"),ObjectId("617282a3a4bb72d733b5c6d8"),ObjectId("617282a3a4bb72d733b5c6d9")]}
> db.FirstCol.update({name:"黎三",sex:"女",age:25,status:"A"},{$set:{'age':28}})WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.FirstCol.find().pretty(){"_id" : ObjectId("618904b6258a6c38daf13abd"),"name" : "黎三","sex" : "女","age" : 28,"status" : "A"}{"_id" : ObjectId("618904b6258a6c38daf13abe"),"name" : "王六","sex" : "男","age" : 26,"status" : "B"}{"_id" : ObjectId("618904b6258a6c38daf13abf"),"name" : "王五","sex" : "男","age" : 26,"status" : "A","groups" : ["news","sports"]}
> db.FirstCol.remove({name:"黎三",sex:"女",age:28,status:"A"})WriteResult({ "nRemoved" : 1 })
> db.FirstCol.find().pretty(){"_id" : ObjectId("618904b6258a6c38daf13abe"),"name" : "王六","sex" : "男","age" : 26,"status" : "B"}{"_id" : ObjectId("618904b6258a6c38daf13abf"),"name" : "王五","sex" : "男","age" : 26,"status" : "A","groups" : ["news","sports"]}
本页内容是否解决了您的问题?