Lee
Lee

Reputation: 3012

Node.JS: MongoDB update callback returns result with code of function

I have a script updating a MongoDB collection and log the error and result object in its callback function. Every works fine except the result object contains a long chunk of code, which I have no idea how to get rid of. I'm using native MongoDB node.js driver, version 2.0.46.

Code snippet:

var find = {_id:id}, set = {$set:{dt:now}}; 
myCollection.update(find, set, function(err, result) {
    if(err) logger.error(JSON.stringify([find, set]), err.toString());
    else logger.verbose(result);
})

I then receive this set of log entry when no error occurs for the update.

2015-10-29T03:45:13.253Z - verbose: ok=1, nModified=1, n=1, _bsontype=Timestamp, low_=17, high_=1446090311, _bsontype=ObjectID, id=V.ßÂb$#\¾¾«, domain=null, 
close=function g() {
    this.removeListener(type, g);
    if (!fired) {
        fired = true;
        listener.apply(this, arguments);
    }

The function you see in the log entry above is just a small part. The actual "close function" is tens of thousands lines long, so it fills up my log files quickly.

The logger I'm using is Winston.

I'm wondering what I have done wrong to cause such a return? Any advice is appreciated.

Upvotes: 2

Views: 465

Answers (1)

Chandani Patel
Chandani Patel

Reputation: 471

This is not mongodb or native mongodb driver issue.

MongoDB result contains the other details regarding database and row so you are receiving the method in the console.

You need to log the information which you need by accessing the objects available in result object i.e result.ok, result.n, result.nModified something like below,

winston.info(result.ok, result.n, result.nModified);

Upvotes: 2

Related Questions