gpt4 book ai didi

javascript - 无法从 Node.js 连接到 MongoDB

转载 作者:行者123 更新时间:2023-12-03 15:59:39 28 4
gpt4 key购买 nike

我正在尝试连接到 MongoDB 数据库,但收到以下错误消息:

AssertionError
actual: null
expected: RangeError: Maximum call stack size exceeded at isUndefined (<anonymous>:2748:21) at Object.exports.deprecate (<anonymous>:2330:7) at <anonymous>:2332:22 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41
generatedMessage: true
message: "null == [RangeError: Maximum call stack size exceeded]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [RangeError: Maximum call stack size exceeded]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
constructor: ƒ AssertionError(options)
__proto__: Object

也许您会因为我没有检查和重用以前的主题而谴责我。但尽管问题相似,但没有一个与我的情况相符。

对于连接,我遵循本教程:http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/ (查看“连接到 MongoDB”):

const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

// Connection URL
const url = "mongodb://secretoes:thatstotallysecret@mudfeval-shard-00-00-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-01-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-02-uxnqk.gcp.mongodb.net:27017/test?ssl=true&replicaSet=mudfeval-shard-0&authSource=admin&retryWrites=true";;

// Database Name
const dbName = 'moodle';

// Create a new MongoClient
const client = new MongoClient(url);

// Use connect method to connect to the Server
client.connect(function(err) {
assert.equal(null, err);
console.log("Connected successfully to server");

const db = client.db(dbName);

client.close();
});

一旦这么说了,有人可以帮助我吗?我在任何地方都找不到任何东西。我很困惑。

============更新(2018 年 11 月 8 日 - 下午 01:11 UTC+1)

如果我通过控制台运行脚本,就没有问题。但是,我收到一条弃用警告,要求我使用新的解析器。

因此,当我在进行这些更改后在网络浏览器上运行它时,错误消息如下:

VM188:1932 Uncaught 
AssertionError {name: "AssertionError", actual: null, expected: TypeError: qs.unescape is not a function
at parseConnectionString (<anonymous>:52229:75)
at …, operator: "==", message: "null == [TypeError: qs.unescape is not a function]", …}
actual: null
expected: TypeError: qs.unescape is not a function at parseConnectionString (<anonymous>:52229:75) at connect (<anonymous>:68112:3) at connectOp (<anonymous>:68216:3) at executeOperation (<anonymous>:71488:24) at MongoClient.connect (<anonymous>:64885:10) at Object.274.assert (<anonymous>:73718:8) at o (<anonymous>:1:265) at r (<anonymous>:1:431) at <anonymous>:1:460 at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)
generatedMessage: true
message: "null == [TypeError: qs.unescape is not a function]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [TypeError: qs.unescape is not a function]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error

是因为browserify吗?

最佳答案

从您的更新中我了解到您尝试使用 Browserify 通过网络浏览器直接连接到 MongoDB。

我认为这行不通。与 MongoDB 的连接是通过 TCP 连接完成的,该连接在您的浏览器中不可用,或者更准确地说:我非常怀疑这是否像使用 Browserify 那样简单,并且一切正常。您的浏览器中可能没有连接到 MongoDB 的驱动程序,或者许多其他先决条件,这些当然不在我的考虑范围内。

请参阅此以获得合适的答案:Connecting to mongodb through the browser?

关于javascript - 无法从 Node.js 连接到 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204550/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com