marcello3d / node-mongolian

[project inactive] Mongolian DeadBeef is an awesome Mongo DB driver for node.js
https://groups.google.com/group/node-mongolian
zlib License
350 stars 50 forks source link

Insert modifies the passed object - intentional? #101

Open KarneAsada opened 12 years ago

KarneAsada commented 12 years ago

I noticed that when passing an object to insert, the _id property is added to the original object via reference. Is this intentional? It seems slightly strange and I've been cloning the object before passing it to insert to prevent this.

marcello3d commented 12 years ago

Short answer: It is intentional.

I agree it seems strange. I originally implemented this behavior because that's what mongodb-native did. But that's a good enough reason as any to reconsider.

In order to not insert the property I would either have to clone the entire structure or keep track if it needed to be added and remove it again at the end.

I'll keep this issue open for now.

KarneAsada commented 12 years ago

It's good to know I wasn't doing something wrong.

I'll just keep this functionality in mind and make sure I clone the object before insertion if I need to re-use it.

Thanks.