1. 程式人生 > >Node.js使用MongoDB3.4+Access control is not enabled for the database解決方案

Node.js使用MongoDB3.4+Access control is not enabled for the database解決方案

今天使用MongoDB時遇到了一些問題

建立資料庫連線時出現了warnings

出現這個警告的原因是新版本的MongDB為了讓我們建立一個安全的資料庫
必須要進行驗證
後來在外網找到了答案

解決方案如下:

建立管理員

use admin
db.createUser(
  {
    user: "userAdmin", //使用者名稱
    pwd: "123", //密碼
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] //許可權
  }
)

重啟MongoDB伺服器

mongod --auth -
-port 27017 --dbpath <關聯路徑>

(埠預設就是27017可以不指定)

終端最後輸出"[initandlisten] waiting for connections on port 27017",
啟動完成

連線並認證

mongo --port 27017 -u "userAdmin" -p "123" --authenticationDatabase "admin"

新增額外許可權使用者

use test
db.createUser(
  {
    user: "tester",
    pwd: "123",
    roles: [ { role: "readWrite"
, db: "test"
}, { role: "read", db: "reporting" } ] } )
mongo --port 27017 -u "myTester" -p "xyz123" --authenticationDatabase "test"

MongoDB更新了,使用mongoose也不能簡單的建立連線了
必須要新增必要引數

var mongoose = require('mongoose');
var db = mongoose.createConnection('localhost', 'test', 27017, {user: 'tester'
, pass: '123'});

相關推薦

Node.js使用MongoDB3.4+Access control is not enabled for the database解決方案

今天使用MongoDB時遇到了一些問題 建立資料庫連線時出現了warnings 出現這個警告的原因是新版本的MongDB為了讓我們建立一個安全的資料庫 必須要進行驗證 後來在外網找到了答案 解決方案如下: 建立管理員 use admin d

WCF : 修復 Security settings for this service require Windows Authentication but it is not enabled for the IIS application that ho

摘要 : 最近遇到了一個奇怪的 WCF 安全配置問題, WCF Service 上面配置了Windows Authentication. IIS上也啟用了 Windows Authentication, 但是仍然出現IIS沒有啟用Windows Authentication的問題. 在網路上能查到的資料很少.

delphi 10.1編譯專案的時候出現MSBuildToolsPath is not specified for the ToolsVersion解決辦法

今天在使用delphi 10.1編譯專案的時候出現MSBuildToolsPath is not specified for the ToolsVersion "14.0" defined at

The 'microsoft.jet.oledb.4.0' provider is not registered on the local machin 的解決方案

分公司上一新網站,用的也是CMS的模式,為了省事用的access,在64位伺服器上出現此問題。 The 'microsoft.jet.oledb.4.0' provider is not registered on the local machin 直接百度後找了各種解決方

postgis-2.0.dll": %1 is not a valid Win32 application解決方案

下載地址: 連結: https://pan.baidu.com/s/1qLrmqEoFdvf4n9vkw-RSxw 密碼: 63l2 參考部落格: https://blog.csdn.net/atzhangzt/article/details/69788102?locationNu

The method setDate(int, java.sql.Date) in the type PreparedStatement is not applicable for the argum

The method setDate(int, java.sql.Date) in the type PreparedStatement is not applicable for the arguments (int, java.util.Date) preparedStatement

Version 當前jdk版本號 of the JVM is not suitable for the this product.Version:1.8 or greater is required

eclipse對應的jdk版本打不開 解決辦法一:可以更改jdk版本。 解決辦法二:我們要知道 JRE是java執行時環境,包含了java虛擬機器,java基礎類庫。是使用java

前端到後端------HTTP Status 405 ( The specified HTTP method is not allowed for the requested resource )

我的報錯如下:可我前端ajax裡標註了“method:'post',”,後臺“method=RequestMethod.POST”,自始至終都Get沒關係呀,很納悶究竟怎麼跑出來的GET;而且根據url請求根本就沒進入到方法體裡;我的解決方法:至於為什麼這樣,好像是說不加re

AndroidN載入私有庫時報錯:xxx is not accessible for the namespace

谷歌從Android N開始,除了那些在Android NDK提供的庫之外,限制了應用對系統私有庫的載入。既然是限制了,想通過以前的方法去載入庫已經行不通了。暫時想到兩種解決方法,目的是將缺少的so檔案放入apk中的lib目錄中。1.在Android.mk中新增缺少的so檔案

Android N載入系統私有庫時出現is not accessible for the namespace錯誤和針對該錯誤的解決方法

谷歌從Android N開始,除了那些在Android NDK提供的庫之外,限制了應用對系統私有庫的載入。既然是限制了,想通過以前的方法去載入庫已經行不通了。所以目前的解決方法就是把應用需要載入的庫和需要依賴的庫從系統中pull出來,然後整合到自己的應用當中。本文是看了這篇

RAD Studio 報MSBUildToolsPath is not specified for the ToolsVersion "14.0"的錯誤

從上次六一安裝試用RAD,這就樣過了快兩個月了,就想用一下看看,結果報MSBUildToolsPath is not specified for the ToolsVersion "14.0",google了一下,找到原因了,因為我有裝過vs2015,但是真心不好用,就解除

OSCache的原始碼編譯Cache.java 檔案報add(Class, T) in the type EventListenerList is not applicable for the arguments 錯誤的解決

下載了 OSCache的原始碼,需要新增一些功能,匯入Eclipse之後編譯,Cache.java 檔案報如下錯誤: Description Resource Path Location TypeThe method add(Class<T>, T) in the

The requested resource is not available 的9種解決方案

ppi ext con 允許 文件夾 guestbook res http 配置文件 HTTP Status 404(The requested resource is not available)異常主要是路徑錯誤或拼寫錯誤造成的,請按以下步驟逐一排查: 1. 右鍵項目

header field token is not allowed by Access-Control-Allow-Headers in preflight response問題解決

-c 後臺服務 ons flight response 我只 expr 分享圖片 bubuko 今天下午,本來打算使用aioxs在header裏傳一個token給後臺服務器,如下圖所示: 結果,控制臺報了如下的錯: 然後,我不停地百度,不停的改後臺express的he

EXCEL數據匹配:The 'Microsoft.Jet.Oledb.4.0' provider is not registered on the local machin

name 方案 tar use .com 32位 原因 http gis 百度的處理結果: 作者:LisenYang http://blog.csdn.net/lisenyang/article/details/52106492 這篇博文裏面說的,默認設置修改【啟動32應用

[ERR] Node is not empty. Either the node already knows other nodes (check with C

add som round des dea already not cli empty [root@node00 src]# ./redis-trib.rb add-node --slave --master-id4f6424e47a2275d2b7696bfbf8588e

Node.js處理 Access-Control-Allow-Origin (Vue)

第一步:安裝cors庫 npm install koa2-cors   第二步:進入APP.JS檔案 const cors=require('koa2-cors')   //引入 第三步:USE app.use(cors()); &

The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.

錯誤程式碼示例: 其中strCD[i]為陣列的一個值 T_BUSINESSTYPE typeModel = ibusinesstype.FirstOrDefault(t => t.TYPE_CD == strCD[i]); 正確程式碼示例: string strcd =

redis建立叢集時顯示錯誤: [ERR] Node xxx is not empty. Either the node already knows other no...

純手打,轉載請附上本文網址!!! 在redis叢集配置的最後一步,使用命令報錯[ERR] Node xxx is not empty. Either the node already knows other no... redis-trib.rb create --rep

java.util.ConcurrentModificationException: KafkaConsumer is not safe for multi-threaded access

最近在專案中遇到一個錯,搞了很長時間才找到原因,記錄一下,主要報錯的程式碼如下: val rdd1 = r.filter(x=>x.value().contains("history_price