1.添加命令:
db.getCollection('test').insert({ key : ' value ' })
注:key和value都可以加 ' 或 " ,insert不支持批量插入,只能使用for循环插入
2.查询命令:
db.getCollection('test').find({})
注:默认查找集合中全部记录
3.排序命令:
db.getCollection('test').find({}).sort( key :-1 )
注:-1表示降序排序,1表示升序排序
4.分页命令:
db.getCollection('test').find({}).limit( int)
注:limit中直接填写整数
5.条数查询
db.getCollection('test').count()
在对Mongo数据库进行操作shell时,可使用以下命令:
1.show dbs 展示所有数据库
2.use xxx 使用xxx数据库
3.db 显示当前所选数据库
4.db.createUser() 对当前所选数据库创建用户
5.db.auth() 对当前数据库授权