'process.nextTick(function() { throw err; })' - Undefined is not a function (mongodb/mongoose)

后端 未结 3 642
有刺的猬
有刺的猬 2020-12-16 15:50

I\'m trying to connect to my mongodb using nodejs and socket.io. I am able to connect to the database because I get \'connection accepted\' in my console bu

3条回答
  •  无人及你
    2020-12-16 16:31

    From the provided information, it looks like you are using mongodb 2.0 driver. The db.collectionNames method was dropped. Check out the "Db Object" section of this page - https://github.com/mongodb/node-mongodb-native/blob/0642f18fd85037522acf2e7560148a8bc5429a8a/docs/content/tutorials/changes-from-1.0.md#L38

    They've replaced it with listCollections. You should get the same effect with:

    mongoose.connection.db.listCollections().toArray(function(err, names) {
        if (err) {
            console.log(err);
        }
        else {
            names.forEach(function(e,i,a) {
                mongoose.connection.db.dropCollection(e.name);
                console.log("--->>", e.name);
            });
        }
    });
    

提交回复
热议问题