2017-12-15 5 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(); 
         }); 
         }); 

Antwort

0

Die find Methode werden alle Dokumente zurück, die dem Filter entsprechen. Sie können jedoch mit find().limit() begrenzen.

Auch wenn Sie etwas wie Paging ausführen möchten, können Sie find().skip() verwenden, um einige Dokumente zu überspringen und dann das Ergebnis erneut zu begrenzen.

+0

Anirudh, danke für Ihre Antwort. Mit dem obigen Code bekomme ich nur die ersten 101 Datensätze. Ich habe 30K Zeilen in meiner Sammlung und ich erwarte mit diesem Code 30K Zeilen in meine Konsole zu bekommen. Ich bin sicher, dass ich etwas vermisse, aber nicht weiß, was es ist. –

Verwandte Themen