1 数据库
1.1 创建数据库
use xxx
1.2 删除数据库
db.dropDatabase()
2 集合
相当于mysql的table
2.1 创建集合
db.createCollection("集合名称")
2.2 删除集合
db.dropCollection("集合名称")
3 文档
相当于mysql的表记录
3.1 新建文档
db.collectionName.save({json数据})
db.collectionName.insert({json数据})
3.2 查询文档
3.2.1 基本查询
db.collectionName.find({条件})
db.collectionName.find({条件},{field:ifshow})
ifshow控制是否显示字段取值为0或1
3.2.2 and查询
db.collectionName.find({$and:[{条件1},{条件2}])
3.2.3 or查询
db.collectionName.find({$or:[{条件1},{条件2}])
3.2.4 分页查询
db.collectionName.find({条件}).limit(取多少数据).skip(跳过多少)
3.2.5 排序查询,1为正序,-1为倒叙
db.collectionName.find({条件}).sort({fieldName:1})
3.3 更新数据
db.collectionName.update({条件},{更新内容},{可选项})
更新内容如果为纯内容的话直接覆盖
如果为{$set:{内容}}的话为局部更新
如果为{$inc:{内容}}的话为自增
3.4 删除数据
db.collectionName.remove({条件})
4 索引
4.1 创建索引
db.collectionName.createIndex({field:sort,...})
4.2 查询索引
db.collectionName.getIndexes()
4.3 删除索引
db.collectionName.dropIndex(parameter)
parameter::可选索引名称
parameter:可选创建参数
5 查询计划
类比mysql的explain
db.collectionName.find().explain()