basic
# 查看所有数据库show dbs
# 创建或选择数据库use articledb
# 查看当前数据库名dbdb.dropDatabase()like table
db.createCollection("users")show collectionsdb.users.drop()- 如果post集合不存在,则会隐式创建
db.post.insert({"title":"Next.js 16","content":"This release provides the latest improvements to Turbopack, caching, and the Next.js architecture. Since the previous beta release, we added several new features and improvements"})
-- 批量插入db.post.insertMany([{"title":"title one","content":"content one"},{"title":"title two","content":"content two"},])db.post.find()
-- 单条查询db.post.findOne({title: 'title one'})
-- 查询返回指定字段db.post.find({title: 'title one'},{title:1,content:1,_id:0})-- 更新id为1的title的值db.post.update({_id:"1"},{$set:{title:'title one update'}})
-- 修改所有符合条件的数据db.post.update({_id:"1"},{$set:{title:'title one update'}},{multi:true})db.post.remove({_id: '1'})
-- 删除全部db.post.remove({})