[英]Not able to connect to mongoDB atlas
我已經正確安裝了所有東西,但不知道發生了什么。 這是代碼
// Connect to MongoDB
const dbURI = 'mongodb+srv://<username>:<password>@blogging-site.mantx.mongodb.net/Blogging-site?retryWrites=true&w=majority';
try {
// Connect to the MongoDB cluster
mongoose.connect(dbURI,{ useNewUrlParser: true, useUnifiedTopology: true },
() => console.log(" Mongoose is connected")
);
} catch (e) {
console.log("could not connect");
}
我的 VS 代碼 treminal 中的錯誤是 - 錯誤:queryTxt ETIMEOUT blogging-site.mantx.mongodb.net
在 QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19) { errno: undefined, code: 'ETIMEOUT', syscall: 'queryTxt', hostname: 'blogging-site.mantx.mongodb.net' } 我是遵循網絡忍者教程,希望我沒有按照他的指示離開任何步驟。 我之前使用過 mongoDB 地圖集,並在我的計算機中安裝了 mongodb。 這會產生什么問題嗎?
沒有問題,因為“我可以連接”到它。
我可以連接到它
我,一個你不認識的人,一個很可能在世界另一端的人
可能是一個懷有惡意的人(盡管我不是)。
這可能是連接問題(由於互聯網不好或其他原因),但更大的問題是
我可以連接到它
因此,也許您希望在將 MongoDB URI 部分公開以供所有人查看之前將其保留,除非您想要一個邪惡的人竊取用戶信息、session 數據,以及您的數據庫中沒有的數據。
快樂學習!!!
在評論后編輯以下是您在 mongoose 中應該學習的內容:
-setting up initial(also called default) connection with mongoose.connect()
-configuring schemas with mongoose.Schema()
-compiling models with schemas with mongoose.model()
-saving the doc with mongoose.save()
-querying the database(findOne, find, deleteOne, updateOne, findById are the
ones I find most used)
也許當你習慣了所有這些時,你可以開始學習填充(你可能會在更大的項目中需要它)、創建多個連接和導出模式模式、驗證、mongooseJs 的中間件等等,我確信你會自己調查的。
至於“你能告訴我你是如何連接到地圖集的嗎?” :
我剛剛復制了您的代碼並在我的計算機上運行。 就那么簡單。 dbURI 變量中的字符串是連接到數據庫圖集的一種方式。 你把它給了我,我使用它並連接到它。
Error: queryTxt ETIMEOUT
當客戶端嘗試從 DNS 檢索blogging-site.mantx.mongodb.net
的 TXT 記錄時,它超時。
在同一台機器上,使用 nslookup 進行測試以檢索 TXT 記錄,如果您的 DNS 提供程序不支持,您將需要使用非 SRV 連接字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.