0
所以我试图用节点将数据输入到一个mongodb集合中。据我可以告诉我有权访问该集合。用MongoDb和Node.js输入数据
var collection = db.collection("whatsGoingOnEvents");
if(collection){
console.log("hitting stream");
var stream = collection.find({time: parsedObject.time, endTime: parsedObject.endTime, lon:parsedObject.lon,lat:parsedObject.lat}).stream();
console.log(stream);
stream.on("data",function(data){
console.log("data");
console.log(data);
if(!data){
collection.insert(parsedObject);
console.log("hitting insert");
}
});
stream.on("end",function(){
//dosomething
});
}
parsedObject可能会或可能不会有所有这些领域的 - 应该很重要?我认为如果该字段不存在,那么collection.find()只是寻找时间来“未定义”,这在技术上仍然是一个值。
我从来没有击中console.log("data")
所以我从不插入文件。我一直在尝试关注this link。
所以我不知道为什么插入没有发生。我知道,没有什么被添加from db.collection.stats();
,还告诉我集合的大小为0
哦也,这是我使用连接到Mongo-什么
var mongo = require('mongodb').MongoClient;
EDIT--
我试着回答下面 - 导致这种错误 -
lib/mongodb/connection/server.js:481
throw err;
^
Error: Cannot use a writeConcern without a provided callback
at insertAll (/Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn/node_modules/mongodb/lib/mongodb/collection.js:332:11)
at Collection.insert (/Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn/node_modules/mongodb/lib/mongodb/collection.js:91:3)
^因为我还没有添加回调到插入上述发生。
ah - 如果没有结果返回,是否有事件发生? – praks5432 2013-03-28 10:59:59
也,这是给我一个错误 - 错误:不能使用writeConcern没有提供的回调 – praks5432 2013-03-28 11:01:20
我不认为有'没有结果'事件,但流只是真正有用的,当你运行查询可能会返回大量的结果;在这种情况下,结果的最大数量是1. Wrt你的错误,请参阅http://stackoverflow.com/a/14410066/893780(我相应地更新了我的答案)。 – robertklep 2013-03-28 11:06:03