|
2.2.0 changed the behavior of ObjectId#toString and ObjectId#valueOf. In 2.0.x
ObjectId#toString would return an object ID string, like "50490f24a5b26b22e7000001", while in 2.2.0 it returns a string like "ObjectId(\"50490f24a5b26b22e7000001\")".
This change breaks our MR jobs that use object IDs as object literal keys, e.g.
var userEvent = {};
userEvent[this.user_id] = 1;
emit(key, userEvent);
Through some experimentation we found that ObjectId#valueOf in 2.2.0 returns a representation that we need, i.e. "50490f24a5b26b22e7000001". However, we also found that the behavior of ObjectId#valueOf was different in 2.0.x, where it return the object itself.
We couldn't find any documentation on ObjectId#valueOf and we're concerned that its behavior could change in future releases again. Can we rely on #valueOf remaining the same in the future? Or is there a more reliable way to convert ObjectId to a string, given that the 2.2.0 ObjectId#toString result is unusable for our purposes?
|