Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long causes Client Error: bad object in message: invalid bson type #36

Open
kevinoid opened this issue Feb 24, 2014 · 0 comments
Open

Comments

@kevinoid
Copy link

Using the MongoDB Long/NumberLong type in queries can cause a few different errors in mquery. For example:

mquery(collection).update(
    {_id: "example"},
    {_id: "example", number: mongodb.Long.fromString("12345")},
    {upsert: true},
    function(err, num) {
      if (err) throw err;
      console.log("Updated " + num);
    }
);

Causes Client Error: bad object in message: invalid bson type while

mquery(collection).update(
    {_id: "example"},
    {number: mongodb.Long.fromString("12345")},
    function(err, num) {
      if (err) throw err;
      console.log("Updated " + num);
    }
);

Causes Client Error: bad object in message: bson length doesn't match what we found

The root of the problem appears to be that utils.clone and utils.cloneObject do not properly handle the mongodb.Long type (and likely Timestamp and possibly other non-native BSON types).

This could be fixed by adding another obj.constructor special case to clone for these types. Alternatively, the reason that the clone doesn't currently work is that functions are cloned by converting their source to a number and calling the Function constructor, which doesn't work for the functions on the Long prototype. In either case, it shouldn't be too bad to fix.

Cheers,
Kevin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant