2017-12-15 7 views
0
/*  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(); 
         }); 
         }); 

答えて

0

findメソッドは、フィルタに一致するすべてのドキュメントを返します。 find().limit()を使用して制限できます。

また、ページングのような処理を実行する場合は、find().skip()を使用して少数のドキュメントをスキップし、結果を再度制限することができます。

+0

Anirudh、ご返信ありがとうございます。上記のコードでは、最初の101レコードしか取得していません。私は私のコレクションに30Kの行があり、私はこのコードで私のコンソールに30Kの行を得ることを期待しています。私は何かを逃していると確信していますが、それが何であるか分からない。 –

関連する問題