以名称为bob的数据库为例
use bob 如果数据库不存在,则创建数据库,否则切换到指定数据库
show dbs 查看所有的数据库
db.dropDatabase() 删除当前切换到的数据库
db.createCollection("line") 创建集合(表)line
show collections/tables 产看所有集合(表)
db.line.drop() 删除line集合
db.line.insert({ title: "教程A" }) 插入数据
db.line.update({ ‘title‘: ‘教程A‘ },{ $set:{‘title‘: ‘教程B‘} }) 更新数据
db.line.remove({ ‘title‘: ‘教程A‘ }) 删除数据
db.line.find().pretty() 查询所有并返回格式化的数据
db.line.findOne() 查询只返回第一笔数据
db.line.find({ ‘title‘: ‘教程A‘,‘name‘: ‘名称A‘ }).pretty() 查询title是教程A并且name为名称A的数据
db.line.find({$or:[{‘title‘: ‘教程A‘},{‘name‘: ‘名称A‘}] }).pretty() 查询title是教程A或者name为名称A的数据
原文:https://www.cnblogs.com/huaxiaguyuan/p/12768931.html