One of the nodejs operations mongodb (install mongodb)

1. Install and configure password login

  • 1. Download address

  • 2. Create a super administrator user

    use admin
    db.createUser({
      user:'root',
      pwd:'root', 
      roles:[{role:'root',db:'admin'}]
    })
    # Successfully added user: {
          
          
    # 	"user" : "root",
    # 	"roles" : [
    # 		{
          
          
    # 			"role" : "root",
    # 			"db" : "admin"
    # 		}
    # 	]
    # }
    
  • 3. Modify the configuration file

    #mac电脑是:/usr/local/etc/mongod.conf
    # 1.先拷贝一份
      cp mongod.conf mongod_bank.conf
    # 2.在mongod.conf中添加
    security:
    	authorization: enabled
    
  • 4. Stop runningmongodb

    use admin;
    db.shutdownServer();
    
  • 5. Use commands to run in the backgroundmongodb

    nohup mongod &
    

Two, create a separate password for the database

  • 1. Create a secret order

    use nest_cms
    db.createUser( {
          
          
      user: "nest_cms",
      pwd: "123456",
      roles: [ {
          
           role: "dbOwner", db: "eggcms" } ]
    })
    
  • 2. [ mongodbBuilt-in role](https://www.cnblogs.com/zzw1787044/p/5773178.html

Guess you like

Origin blog.csdn.net/kuangshp128/article/details/103855669