nodejs - mongodb native find all documents

前端 未结 4 2073
迷失自我
迷失自我 2020-12-30 08:14

Following an example from the mongodb manual for nodejs, I am finding all documents from a db as follows

mongo.Db.connect(mongoUri, function (err, db) {
             


        
4条回答
  •  星月不相逢
    2020-12-30 08:24

    You can stream the results of a node.js native driver's query by calling stream() on the returned cursor:

    var stream = collection.find().stream();
    stream.on('data', function(doc) {
        console.log(doc);
    });
    stream.on('error', function(err) {
        console.log(err);
    });
    stream.on('end', function() {
        console.log('All done!');
    });
    

提交回复
热议问题