2

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.

4
  • Log the result to the console and see the result. I'm curious if this is a mongodb problem or a logger problem. Commented Oct 29, 2015 at 4:16
  • Nocturno, it's the same as the log file. I'm using Winston for logging. I'd think it's a MongoDB thing, coz if Mongo doesn't return such content, logger won't add in extra stuff. Commented Oct 29, 2015 at 4:23
  • this is a response from mongodb....if you update in mongo shell,you'll find this response also Commented Oct 29, 2015 at 5:20
  • Subham, I understand it's from MongoDB, but I don't agree it will come from mongo shell. For what you would need a response of tens thousands of line of JS code? Commented Oct 29, 2015 at 6:12

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.