无法使用 Node.js 连接到 MongoDB。
这是我的代码(mdb.js):
var MongoClient = require('mongodb').MongoClient, format = require('util').format;
MongoClient.connect('mongodb://localhost:3000', function(err,db){
if(err){
throw err;
} else {
console.log("Connected");
}
db.close();
});
Run Code Online (Sandbox Code Playgroud)
Node mdb.js 打印 MongoError:
我已经用谷歌搜索并询问了人们这个问题,但无法理解其含义。我知道我的解决方案不正确,但我希望它可以帮助(它在 JS 上):
let C = [1, 3, 1, 4, 2, 3, 5, 4],
Y = 4;
function solution(X, A) {
var leaves = [];
var i = 0;
var result = -1;
for (i = 0; i < A.length; i++) {
if (typeof leaves[A[i]] == 'undefined') {
leaves[A[i]] = i;
}
}
if (leaves.length <= X) {
return -1;
}
for (i = 1; i <= X; i++) {
if (typeof leaves[i] == 'undefined') {
return -1;
} else …Run Code Online (Sandbox Code Playgroud)