ZhengXingchi / ZhengXingchi.github.io

Apache License 2.0
0 stars 0 forks source link

mongodb #87

Open ZhengXingchi opened 4 years ago

ZhengXingchi commented 4 years ago

参考文献

mongodb官方网站

mongodb中文网

Mongodb 4.2 中文文档

ZhengXingchi commented 4 years ago

数据库相关操作

show dbs 展示数据库 use databesename 创建活切换数据库 db展示当前的数据库 db.dropDatabase()删除当前的数据库

ZhengXingchi commented 4 years ago

集合相关操作

db.createCollection('test')显式创建集合 show collections展示当前数据库的集合 db.test.drop()删除test集合

ZhengXingchi commented 4 years ago

集合CURD

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字段