1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #测试数据录入 for(i=0;i<10000;i++){db.amtuser.insert({"uid":i,"name":"mongodb","age":6,"date":newDate()})}
#统计集合中行数 > db.amtuser.count() 3 #查询集合中所有数据 > db.amtuser.find() { "_id" : ObjectId("672b05c6df37ce934a286665"), "id" : 1, "name" : "张三", "age" : 20, "gender" : "男" } { "_id" : ObjectId("672b07bedf37ce934a286666"), "id" : 2, "name" : "李四", "age" : 28, "gender" : "男" } { "_id" : ObjectId("672b07d3df37ce934a286667"), "id" : 3, "name" : "王五", "age" : 18, "gender" : "女" }.... #格式化查询 json格式显示 > db.amtuser.find().pretty() { "_id" : ObjectId("672b05c6df37ce934a286665"), "id" : 1, "name" : "张三", "age" : 20, "gender" : "男" }.... #条件查询 > db.amtuser.find({id:1}) { "_id" : ObjectId("672b05c6df37ce934a286665"), "id" : 1, "name" : "张三", "age" : 20, "gender" : "男" } #删除集合中所有记录 > db.amtuser.remove({}) WriteResult({ "nRemoved" : 3 }) #每页显示50条记录: > DBQuery.shellBatchSize=50;
#集合中索引+数据压缩存储之后的大小 > db.amtuser.totalSize()
|