gpt4 book ai didi

javascript - MongoDB——client.open() 返回 "undefined in not a function"

转载 作者:可可西里 更新时间:2023-11-01 09:59:02 26 4
gpt4 key购买 nike

这是我所拥有的:

var express = require('express');
var MongoClient = require('mongodb').MongoClient;
var Server = require('mongodb').Server;

var app = express();

var client = new MongoClient(new Server('localhost', 27017, {}), {});

client.open(function(err, client){
//callback
});

当我运行它时,它指向 open 方法所在的行并显示“undefined is not a function”。我做错了什么?

最佳答案

来自mongo docs :

var MongoClient = require('mongodb').MongoClient

// Connection URL
var url = 'mongodb://localhost:27017/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
console.log("Connected correctly to server");

db.close();
});

关于javascript - MongoDB——client.open() 返回 "undefined in not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31071275/

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