0
我想删除整个集合,但它不与下面的nodejs代码一起工作。 mongodb的内同一作品使用命令[db.collection.remove()]mongoclient删除收集nodejs
没有错误,但低于返回事件的计数为0
smevents.count(function(err, count) { console.log("There are " + count + " records."); });
除去的条目示出了如0从如下─
console.log("Removed collection entries " + collectionName + "," + removed);
使用的集合名是按照从所获得的一个 -
db.collectionNames(function(err, collections){ console.log(collections); });
下面是代码 -
function removeMongoDBCollection(db, collectionName, callback) {
console.log('collectionname ' + collectionName);
db.collectionNames(function(err, collections){
console.log(collections);
});
db.collection(collectionName, {}, function(err, smevents) {
console.log('Error Getting collection ' + err);
smevents.count(function(err, count) {
console.log("There are " + count + " records.");
});
smevents.remove({}, function(err, removed) {
console.log('Error Removing collection ' + err);
console.log("Removed collection entries " + collectionName + "," + removed);
db.close();
callback(err);
});
});
}
我不知道是什么你的问题。你可以编辑你的问题,澄清你想要做什么,什么不工作?您是否尝试删除集合本身或仅删除其中的文档? – JohnnyHK