【发布时间】:2018-08-11 15:11:24
【问题描述】:
我正在尝试将 800 个对象插入到 mongodb 中,并且我正在尝试防止一次又一次地插入相同的元素。我会检查集合是否存在,不要插入,否则插入 800 个对象。
mongoose.connect('mongodb://localhost/testDB', function(err,db){
if(err){
console.log(err)
}
db.listCollections().toArray(function(err, collections){
console.log(collections);
});
});
但是控制台抛出错误并显示:
(node:24452) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: db.listCollections is not a function
(node:24452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我现在卡住了,谢谢。
【问题讨论】:
标签: javascript node.js mongodb mongoose