So, I am following the Node.js training course at tutsplus.com, which so far has been wonderful.
I am participating in a MongoDB lesson and I peeled off a bit. I am not sure why this does not work for me as it works in the video and my code is the same. All I can imagine is an update, since the course was made a year ago.
From trying to console.log at different points, I think that the data is not inserted correctly at the beginning and therefore nothing is returned.
Everything seems to work as expected, except for the callback for cursor.toArray() .
I am currently studying node and mongodb, so please bear with me if I make an obvious mistake.
I was instructed to write the following file, and then execute it on the command line.
EDIT:
I narrowed down the problem to an insert script. When inserting data through the CLI, it will return it back.
var mongo = require('mongodb'), host = "127.0.0.1", port = mongo.Connection.DEFAULT_PORT, db = new mongo.Db('nodejsintro', new mongo.Server(host, port, {})); db.open(function(err){ console.log("We are connected! " + host + " : " + port); db.collection("user", function(error, collection){ console.log(error); collection.insert({ id: "1", name: "Chris Till" }, function(){ console.log("Successfully inserted Chris Till") }); }); });
source share