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

Already on GitHub? Sign in to your account

Fix, an object with type ObjectID should be able to convert itself #71

Merged
merged 1 commit into from Feb 24, 2014

Conversation

Projects
None yet
2 participants
Contributor

pandaiolo commented Feb 23, 2014

I propose this small addition to ObjectID, so that when used as a caster, it does not throw an exception.

Example :

var myObjectId = new ObjectID();
var idWithUnknownType = myObjectId;
// Some code later, use ObjectID() to force the type
idWithUnknownType = ObjectID(idWithUnknownType);

The above code works with basic javascript types, like Object, String, Number, but not ObjectID

MongoDB BSON ObjectID is used in many third party code that deals with serialization, database callbacks, string IDs, etc, which would make it handy if the ObjectID type can cast itslef, in many cases.

I included a test case for this behaviour, not sure if it's at the right place.

The fact that the whole test suite ran without a glitch let me propose this pullback. Let me know if there is a reason why ObjectID cannot be enhanced with this behaviour. Thanks !

@christkv christkv merged commit 6ff7867 into mongodb:master Feb 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment