question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logging a MongoDB ObjectID directly prints binary buffer

See original GitHub issue
var mongodb = require('mongodb');
var oid = new mongodb.ObjectID();

var winston = require('winston');

console.info(oid);
winston.info(oid);

Result:

553753a3e208f62631e6daa8
info:  _bsontype=ObjectID, id=U7S£ö&1æÚ¨

This is possibly related to #500, although it was not fixed by it.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
michaelfreundcommented, Feb 27, 2017

+1

using .toString() works but is extremely frustrating. any plans on fixing this?

currently doing stuff like JSON.parse(JSON.stringify(post)) 🙈

3reactions
mostrcommented, Feb 27, 2017

Is there any solution for this other than patching external lib as @kaetemi said (using latest release of winston)? I log MongoDB-stored object that has some ObjectID properties like this

logger.debug('Definition saved', definition)

and for these ObjectID props I get crap like _bsontype=ObjectID, 0=88, 1=54, 2=212, 3=140, 4=168, 5=147, 6=113, 7=163, 8=107, 9=62, 10=237, 11=253 out 😦

I was trying to use rewriters/filters for that but with no luck (cannot reliably detect/rewrite these props)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Log Messages — MongoDB Manual
When working with MongoDB structured logging, the third-party jq command-line utility is a useful tool that allows for easy pretty-printing of log entries,...
Read more >
nodejs mongodb object id to string - Stack Overflow
Try this: user._id.toString(). A MongoDB ObjectId is a 12-byte UUID can be used as a HEX string representation with 24 chars in length....
Read more >
How To Find A MongoDB Document By Its BSON ObjectID ...
This article explains how to find a MongoDB document by the BSON ObjectID using Golang with easy to follow detail and example code....
Read more >
Spring Data MongoDB - Reference Documentation
The core functionality of the MongoDB support can be used directly, ... The Spring Data MongoDB 4.x binaries require JDK level 17 and...
Read more >
How To Perform CRUD Operations in MongoDB - DigitalOcean
MongoDB is a persistent document-oriented database used to store and process data in the form of documents. As with other database management ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found