Open nikitaeverywhere opened 3 years ago
First of all +1 for the cats 🤣
But on a serious note: Came here to look for a solution for exactly @ZitRos 's problem. I was happily flattening objects before throwing them into mongo/mongoose updates until I stumbled upon this behaviour.
Hello! Thanks for the great and popular library.
This is a kind of library design-level question.
The code:
Expectation
Actual result
Question
Why flatten any non-Object-prototype objects? I.e. why not only objects that satisfy
Object.getPrototypeOf(obj) === Object.prototype
? Is there a use-case for flattening custom (prototyped) objects?My use case
I was happily using this convenient library with MongoDB queries, to flatten this for example (oversimplified):
However, soon I realized that Mongo's
ObjectID
also gets flattened in a very weird way:This breaks MongoDB's
updateOne
.Suggestions
pureObjectsOnly
. But this IMO is weird with the presence of thesafe
option.safe
also not transforming non-"pure" objects, as well as arrays (this is enough for my case, as I never update arrays like this in MongoDB).Request for comments
I would be happy to know any opinions on this and contribute. Thanks!