我的nodejs app中有以下代码:
db.open(function(err, db) {
while (item = stream.read())
{
var parsedDate = parseDateFromString(item.title);
var movieName = parseNameFromString(item.title);
var channelName = parseChannelFromString(item.title);
//var doc = { "name": movieName, "channel": channelName, "showed": parsedDate, "showDate": parsedDate.format(), "run_id": new Date().toString()};
var doc = { "name": movieName, "channel": channelName, "showed": parsedDate, "run_id": new Date().toString()};
db.collection('programs', function(err, collection) {
collection.find({'name' : doc.name, "channel" : doc.channel}).count(function(countErr, count) {
console.log('count!');
if(count == 0)
insertDocument(collection, doc);
else
console.log('Found match from db with name ' + matchDoc.name);
});
});
} // End of while
}); // End of Open
问题就是数!永远不会报道。所以collection.count没有调用它的回调。我检查了collection.find被多次调用。什么可能导致这个问题?