when I run the simple code below to insert a new document:
collectionUsers.insert({'name':'john'},function(err,records){
if (err) throw err;
console.log("Id of new document added = " + records[0]._id);
});
I get the following errors:
catch(err) { process.nextTick(function() { throw err}); }
^
TypeError: Cannot read property '_id' of undefined
Doesn't the callback function return an array? I'm just trying to get the id of the new document and save it in a variable for future use. Thanks for your help.
Alternatively, if I use insertOne instead, I get this output: Id of new document added = {"ok":1,"n":1}
But I want to use insert...