win10安装MongoDB 5.0

1.首先去官网下载安装包:https://www.mongodb.com/try?tck=docs_navbar

2.安装过程一路下一步就行,选择complete安装,可以勾选安装Compass工具

3.安装完成后,登录Compass工具,连接上MongoDB,在工具右下角执行命令创建admin用户:

use admin

db.createUser({
    "user":"admin","pwd":"123456",
    "roles":[
        {role:"userAdminAnyDatabase", db: "admin"}, 
        {role:"readWriteAnyDatabase", db: "admin"} 
]});

  

 

4.默认情况下,MongoDB安装完成后不允许远程访问,可以通过配置实现远程访问

在路径:C:\Program Files\MongoDB\Server\5.0\bin下找到 mongod.cfg 文件,修改net下bindIp: 127.0.0.1,0.0.0.0,security下填加:authorization: enabled

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: D:\Program Files\MongoDB\Server\5.0\data
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path:  D:\Program Files\MongoDB\Server\5.0\log\mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,0.0.0.0

#processManagement:

security:
 authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

修改完成后,打开CMD,重启MongoDB,执行net stop mongodb  再执行net start mongodb

appsettings.json

 "MongoOptions": {
    "BooksCollectionName": "Books",
    "ConnectionString": "mongodb://localhost:27017",
    //"ConnectionString": "mongodb://admin:123456@1.1.1.1",
    "DatabaseName": "BookstoreDb"
  }

  

 

posted @ 2021-08-06 17:32  小丑不戴面具  阅读(1237)  评论(0编辑  收藏  举报