Josh Myerson Josh Myerson - 3 months ago 10x
Node.js Question

Node.js - Display mongoDB documents with console.log (No Shell)

I am using a mongoDB server that is located on another machine. My question is how can I display all the documents that were found with console.log? Currently my main.js script is this:

// Connect to Mongo
MongoClient.connect('mongodb://', function(err, db) {

// Handle errors
assert.equal(null, err);
// Insert data
// Count data
db.collection('ExpressOrder').find().count().then(function(numItems) {
console.log(numItems); // Use this to debug
// Display all data in db
var found = db.collection('ExpressOrder').find();
console.log(found); // Use this to debug

The data is properly inserted, and counts properly, but I just now need to know how do I display all the documents to the console with console.log.


Have you tried this?

var found = db.collection('ExpressOrder').find();
found.each(function(err, doc) {
    assert.equal(err, null);
    if (doc != null) {