Javascript node.js和mongodb native:等待集合非空

Javascript node.js和mongodb native:等待集合非空,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,我正在使用node.js和本机mongodb驱动程序(node mongodb native) 我当前的项目使用node.js+now.js+mongodb 系统基本上将数据从浏览器发送到node.js,node.js由haskell处理,然后再次反馈到浏览器 通过form和node.js将文本插入名为“messages”的mongo db集合中。 haskell线程读取条目并将结果存储在db集合“results”中。这个很好用 但是现在我需要javascript代码来等待结果出现在集合结果中

我正在使用node.js和本机mongodb驱动程序(node mongodb native)

我当前的项目使用node.js+now.js+mongodb

系统基本上将数据从浏览器发送到node.js,node.js由haskell处理,然后再次反馈到浏览器

通过form和node.js将文本插入名为“messages”的mongo db集合中。 haskell线程读取条目并将结果存储在db集合“results”中。这个很好用

但是现在我需要javascript代码来等待结果出现在集合结果中

伪代码:

   wait until the collection result is non-empty.
   findOne() from the collection results.
   delete the collection results.
我目前连接到mongodb的方式如下:

    var mongo = require('mongodb'),
    Server = mongo.Server,
    Db = mongo.Db;

    var server = new Server('localhost', 27017, {
        auto_reconnect: true
    });
    var db = new Db('test', server);
我的haskell知识相当不错,但不是我的javascript技能。
所以我做了大量的搜索,但没能走多远。

解决办法是使用这个库

var async=require('async');
全球账户=-1;
异步的(
函数(){

return globalCount解决方案是使用库

var async=require('async');
全球账户=-1;
异步的(
函数(){

return globalCount很高兴你解决了这个问题,我打算写一些类似的东西:

setTimeout(function(){ 
   db.collection('results',function(coll){
      coll.findOne({}, function(err, one){
        if( err ) return callback(err);
        coll.drop(callback); //or destroy, not really sure <-- this will drop the whole collection
      });
   });
} ,1000);
setTimeout(函数(){
db.collection('结果',函数(coll){
coll.findOne({},函数(err,one){
if(err)返回回调(err);

coll.drop(callback);//或destroy,不太确定很高兴你解决了它,我打算写一些类似的东西:

setTimeout(function(){ 
   db.collection('results',function(coll){
      coll.findOne({}, function(err, one){
        if( err ) return callback(err);
        coll.drop(callback); //or destroy, not really sure <-- this will drop the whole collection
      });
   });
} ,1000);
setTimeout(函数(){
db.collection('结果',函数(coll){
coll.findOne({},函数(err,one){
if(err)返回回调(err);

coll.drop(callback);//或destroy,不太确定嘿,谢谢你的回答。我以为我自己找不到解决方案,所以你的回答会让我安全。(我只是在一个开源项目的实现者会议上,所以我们必须快速编码…).嘿,谢谢你的回答。我以为我自己找不到解决方案,所以你的回答会让我安全。(我只是在一个开源项目的实施者会议上,所以我们必须快速编码…)。