这是我的代码:
var environment = "ClientUnitTests";
//set up mongodb
var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Grid = require('mongodb').Grid,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');
var db = new Db('test',new Server('localhost',27017),{safe:true});
db.open(function(err, db) {
assert.equal(null, err);
});
var users = db.collection("users");
//Clean up data in test database for clientUnit tests
if (environment == "ClientUnitTests") {
users.remove({},function(err,numberRemoved){
console.log("inside remove call back" + numberRemoved);
});
}
基本上,当应用程序以“ClientUnitTests”模式启动时,我试图从我的用户集合中删除所有数据。不幸的是,console.log 语句永远不会触发(也通过在那里设置一个从不触发的断点来验证)。
删除此集合中的所有文档我做错了什么?