MongoDB数据库创建用户及常用命令
生活随笔
收集整理的這篇文章主要介紹了
MongoDB数据库创建用户及常用命令
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
MongoDB數(shù)據(jù)庫無認(rèn)證啟動命令
mongod -f /mongodb/etc/mongo.conf有認(rèn)證的啟動命令
mongo -f /mongodb/etc/mongo.conf --auth此時進(jìn)入數(shù)據(jù)庫,需要賬號密碼
MongoDB創(chuàng)建用戶
//啟動無認(rèn)證命令 mongod -f /mongodb/etc/mongo.conf//進(jìn)入mongo數(shù)據(jù)庫 mongo//展示所有庫 show dbs創(chuàng)建一個root用戶權(quán)限
//進(jìn)入admin。如果沒有admin庫,會自動創(chuàng)建admin庫 user admin//創(chuàng)建一個新賬號 用戶名admin 密碼admin 權(quán)限r(nóng)oot db.createUser({user:"admin",pwd:"admin",roles:["root"]})//賬號授權(quán):用戶名 密碼。 回車,返回1,認(rèn)證成功。 db.auth("admin","admin")或者創(chuàng)建一個指定訪問text數(shù)據(jù)庫的用戶
//進(jìn)入test數(shù)據(jù)庫。如果沒有test庫,會自動創(chuàng)建test庫 user test//創(chuàng)建一個新賬號 用戶名root 密碼123456 權(quán)限dbOwner 只能訪問test數(shù)據(jù)庫 db.createUser({user:"root",pwd:"123456",roles:[{role:'dbOwner',db:'test'}]})MongoDB對數(shù)據(jù)庫的基本操作命令:
//創(chuàng)建集合 name集合名稱 options對集合的設(shè)置 db,createCollection(name,options)//刪除集合 db.collection_name.drop()//查看集合 show collections//goods集合下創(chuàng)建一條數(shù)據(jù)可用insert或save db.goods.insert({id:101,'name':'panda'}) db.goods.insert({id:102,'name':'panda1'})//查看集合下文檔內(nèi)容 db.goods.find().pretty() //gt 大于 //lt 小于 //eq 等于 //gte 大于等于 //lte 小于等于 //ne 不等于//刪除集合內(nèi)文檔的內(nèi)容 id為101的數(shù)據(jù) db.goods.remove({"id":101})//刪除當(dāng)前數(shù)據(jù)庫 db.dropDatabase()數(shù)據(jù)導(dǎo)入的三種方式:
//第一種--一條條數(shù)據(jù)導(dǎo)入 db.goods.insert({id:101,'name':'panda'})//第二種--MongoDB Compass 數(shù)據(jù)視圖工具 import導(dǎo)入文件 數(shù)據(jù)視圖工具導(dǎo)入//第三種--無數(shù)據(jù)視圖工具且數(shù)據(jù)非常多 //-d 指定數(shù)據(jù)庫 //-c 指定數(shù)據(jù)集合名稱 //-file 指定本地文件路徑或線上路徑 mongoimport -d db_demo -c user --file /Users/db_user.text更多的mongoDB命令可以查看MongoDB教程,網(wǎng)址:https://www.runoob.com/mongodb/mongodb-update.html
總結(jié)
以上是生活随笔為你收集整理的MongoDB数据库创建用户及常用命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 制造企业产品成本核算功能设计实例
- 下一篇: 最流行的Java IDE有哪些?