Open ZhengXingchi opened 4 years ago
show dbs
展示数据库
use databesename
创建活切换数据库
db
展示当前的数据库
db.dropDatabase()
删除当前的数据库
db.createCollection('test')
显式创建集合
show collections
展示当前数据库的集合
db.test.drop()
删除test集合
db.comment.insert({'articleId':'10000','content':'今天天气真好,阳光明媚','userId':'1001','nickname':'Rose','createdatetime':new Date(),'likenum':NumberInt(10),'state':null})
db.comment.insertMany([{'articleId':'10000','content':'今天天气真好,阳光明媚','userId':'1001','nickname':'Rose','createdatetime':new Date(),'likenum':NumberInt(10),'state':null},{'articleId':'10001','content':'今天要减肥','userId':'1002','nickname':'Tom','createdatetime':new Date(),'likenum':NumberInt(10),'state':null}])
db.comment.find()
db.comment.findOne({'articleId':'10001'})
db.comment.find({},{articleId:1,_id:0})
显示articleId字段不显示_id字段
参考文献
mongodb官方网站
mongodb中文网
Mongodb 4.2 中文文档