使用Nodejs在mongodb中返回的文档find()有多少限制

时间:2017-12-15 01:42:51

标签: node.js mongodb

/*     I am trying to read all the docs available in a collection using below command.`enter code here`
            collection.find({}).toArray(function(err, data)***

            I am getting the data returned if i use limit() command but i can goto limit of 101 rows. 
            My collection has 30K rows and i would like to retrieve all 30K rows of Data as per my business need.`enter code here`

            Is there a limit on how many docs we can pull using toArray command?if so, is there an efficient way of this command please?
            /**
             * http://usejsdoc.org/
             */
 */       
        //Declarations
            var json2html = require('node-json2html');
            var MongoClient = require('mongodb').MongoClient;
            var url = 'mongodb://localhost:27017/Narsi30KDB';
            var str = "";
            var data = "";
            var html= "";
         //Service Name   
            exports.alldocs = (function(req, res) {
        //Mongodb Connection    
                MongoClient.connect('mongodb://localhost:27017', function(err, client) {
                    if (err)
                        throw err;
                        var db = client.db('TestDB1');
                    // Get the documents collection
                    var collection = db.collection('TestCollection1');
                    // Find some documents
                    collection.find({}).toArray(function(err, data) {

                //  console.log(data);

var transform = {"<>" : "div", "html" : "${AGENT CODE} ${CHANNEL} ${TRANSACTION TYPE} ${ACTION TYPE} ${CUSTOMER NAME} ${IMEI} ${SIM} ${MOBILE ISD} ${PRODUCT ISD} ${ACTION DATE} ${LIVE DAYS} ${MOBILE} ${NEW MOBILE} ${BAN} ${BILLING MARKET} ${SUBMARKET} ${PRODUCT CODE}" };

                        var html = json2html.transform(data, transform);
         //Sending data to the browser              
                        res.send(html);
                    //  res.send(data);
                                            });
                    client.close();
                        });
                        });

1 个答案:

答案 0 :(得分:0)

find方法将返回与您的过滤器匹配的所有文档。 但是,您可以使用find().limit()限制它。

此外,如果您想执行分页等操作,可以使用find().skip()跳过几个文档,然后再次限制结果。