mongo中常用的命令

命令使用mongo shell 执行

1.mongo中增加新字段

  mongo shell 进入后执行use table选中要添加字段的库

  db.getCollection('表名').update({}, {$set: {filed1:"",filed2:0}})

2.删除字段

db.getCollection('表名').update({},{$unset:{"字段名":""}},false,true)

3.删除集合

db.counters.drop();  删除counters集合

 4.清空集合数据:db.collection.remove({})

5.查看所有表:show dbs

6.选择某表: use tables;

8.查看表中某集合数据:

 db.collection.find()

原文地址:https://www.cnblogs.com/luqiang213917/p/11764330.html