When inserting new documents in mongodb, ids don\'t look like ObjectId and instead they look like an object.
\"_id\" : {
\"_bsontype\" : \"ObjectID\"
I was having the same issue here: ObjectID not storing hexadecimal value
It's definitely an issue with environments and something strange with the brew installation of MongoDB. I found that uninstalling from brew and reinstalling manually solved my issue. http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
While I didn't figure out from a code/technical standpoint why it is returning the 12-byt BSON ObjectID rather than the Hexadecimal ObjectID... uninstalling MongoDB from brew and reinstalling it manually solved the issue.
That is what an ObjectID is. It is simply an object that contains those properties.
http://docs.mongodb.org/manual/reference/object-id/
ObjectId is a 12-byte BSON type, constructed using:
- a 4-byte value representing the seconds since the Unix epoch,
- a 3-byte machine identifier,
- a 2-byte process id, and
- a 3-byte counter, starting with a random value.
{
"_bsontype" : "ObjectID",
"id" : "U\u0013[-Ф~\u001d$©t",
"generationTime" : 1.43439e+09
}
U\u0013[-Ф~\u001d$©t
is the 12 character binary string which gets converted to the familiar 24 char hex string (55107edd8e21f20000fd79a6
) when the object as a whole is represented as a text value (i.e. its .toString function is invoked)
In Mongoose the documents also have a .id
getter which give you the 24 char hex as a string value.
The malformed ObjectIds are caused by a conflict with the mongoose version that mongoose-q is using. You'll need to update to mongoose-q to version 0.1.0. I was using 0.0.17 previously and saw exactly the same behavior that you saw here.