Skip to content

JSON parser does not cast _id property to ObjectID #11

@axelpale

Description

@axelpale

JSON parse is a nice thing to have for development as the backup is human readable. However, I find it hard to use, because _id properties read from JSON are casted to strings instead of ObjectIDs. They must be casted to ObjectID, see e.g. this StackOverflow entry.

The insertion of a string-typed _id does not cause error by itself, but leads to inconsistent _ids. For example, documents { _id: "57e5714f6c34f946dd337fe3" } and { _id: ObjectId("57e5714f6c34f946dd337fe3") } do not violate _id uniqueness and both can exist in a collection at the same time. This obviously is not desired behavior.

After index.js line 186, one should:

doc._id = new ObjectId(doc._id);

where

var ObjectID = require('mongodb').ObjectID;

I guess one must use the default bson parser until this issue is fixed.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions