BasicDBObject copy() vs. clone() ?

793 views
Skip to first unread message

ikevinjp

unread,
Dec 4, 2011, 6:55:27 AM12/4/11
to mongodb-user
What is the difference between BasicDBObject's copy() and clone()
method?

---

Say, I need to query an existing document from CollectionA. After
retrieving it, I need to change the _id and insert into CollectionB
(and delete the one in Collectinon A as well).

So, I would suppose that I first retrieve it, make a copy() or clone()
- which one ?? - and then use the copied/cloned version to change the
_id, and insert into CollectionB. Then, delete the originally retrieve
object from CollectionA.

---

Kevin.

Karl Seguin

unread,
Dec 4, 2011, 7:20:09 AM12/4/11
to mongod...@googlegroups.com
As a general rule, in Java clone is almost always a shallow copy. If you want to separate objects which really have nothing to do with each other, except for the fact that one started off as a duplicate of another (which sounds like what you want), stick with copy (which is custom-implemented in the mongo driver to do a deep copy).

Karl
Reply all
Reply to author
Forward
0 new messages