title,body,link,tags,view_count,is_answered,score,answer_count
Simple Nodejs MongoDB Express iterate / loop collection,"<p>I am attempting to display a collection - insides mongo shell it is straight forward.</p>

<p>DB = testing<br>
collection = inventory</p>

<pre><code>&gt; use testing
switched to db testing
&gt; db.inventory.find();   // very easy and straight fwd
</code></pre>

<p>My problem is I can't seem to figure it out how to get a handle on the data as it iterates out.  I get the following error:</p>

<blockquote>
  <p>Cannot read property 'find' of undefined</p>
</blockquote>

<pre><code>const express = require('express');
const router = express.Router();
const mdb = require('mongoose');

const MongoClient = require('mongodb').MongoClient;
const mongoDB = ""mongodb://localhost/testing"";  

mdb.connect(mongoDB);
mdb.Promise = global.Promise;

let db = mdb.connection;

router.get('/', function(req, res) {
    db.inventory.find(query).stream()
    .on('data', function(doc){
      // handle doc
      console.log(""raw =&gt; "" + doc);
      console.log(""JSON =&gt; "" + JSON.stringify(doc));
    })
    .on('error', function(err){
      console.log(""Error: "" + err)
    })
    .on('end', function(){
      console.log(""iteration complete"")
    });

});
</code></pre>

<p>Thank you in advance</p>
",https://stackoverflow.com/questions/52188636/simple-nodejs-mongodb-express-iterate-loop-collection,"['node.js', 'mongodb', 'express', 'mongoose']",303,True,0,1
