var MongoClient = require('mongodb').MongoClient , format = require('util').format; MongoClient.connect('mongodb://127.0.0.1:27017/chat', function(err, db) { if (err) throw err; var collection = db.collection('test_insert'); collection.remove({}, function(err, affected) { if (err) throw err; collection.insert({a: 2}, function(err, docs) { var cursor = collection.find({a: 2}); cursor.toArray(function(err, results) { console.dir(results); // Let's close the db db.close(); }); }); }); }); 

Here is a simple code for entering data in the database and their subsequent output to the console. Here is the result:

 [ { _id: ObjectID { _bsontype: 'ObjectID', id: [Object] }, a: 2 } ] 

How to make, that instead of [Object] values ​​were output?

    1 answer 1

    Use method

     ObjectId.toString() //В твоем случае results['_id'].toString() 

    Docks here: https://docs.mongodb.com/v3.2/reference/method/ObjectId/
    And here: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/toString