简体   繁体   中英

How to return a temporary collection in the callback of a mongodb find() using node-mongodb-native?

Is there a way to return a temporary collection from a find() operation instead of a cursor? I am using the node-mongodb-native driver and I want to run a mapReduce on the results of the find() operation. Something like this:

client.open(function(err) {
    client.collection(collectionName, function(err, collection) {
        collection.find( {days_since_epoch: {$gte: query.begin}).toArray(function(err, docs) {
            // Need to run a mapReduce here on the results
            // Preferably on a temporary collection instead of the default cursor or array above
       });
    });
});

There is probably a better way to do this so I would be up for that also. Thanks.

nope but the map-reduce function takes a query so you don't need the find :)

http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#mapreduce

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM