[JAVA-927] "deep copy" for Document Created: 14/Aug/13 Updated: 07/Mar/17 Resolved: 21/Sep/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Alexander Azarov | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Can you please enhance API to provide `deep copy` for a Document object. It was possible in version 2.x of MongoDB Java driver via this simple hack (Scala code): dbo.asInstanceOf[BasicDBObject].copy.asInstanceOf[DBObject] I'm using it in "Subset" library: https://github.com/osinka/subset2/blob/master/src/main/scala/DBO.scala#L97 |
| Comments |
| Comment by Jeffrey Yemin [ 26/Nov/14 ] | |
|
Hi Jon, True, though we would need a different name than copy. If you'd like to suggest an alternative, please open a new issue for it, as this one is about the new Document class in the 3.0.x branch, not about BasicDBObject. Thanks, | |
| Comment by Jon Gorrono [ 26/Nov/14 ] | |
|
Your right, not much you can do... but you can create a new signature and deprecate the old one... it's got a long tail, but it's something. | |
| Comment by Jeffrey Yemin [ 25/Nov/14 ] | |
|
There is no good reason that I can see for BasicDBObject.copy to return Object, but since changing it will break binary compatibility we are kind of stuck with it. | |
| Comment by Jon Gorrono [ 24/Nov/14 ] | |
|
The comment for copy() is:
But it returns an java.lang.Object ... is that something to do with the the Map having Object as a value type, or should I create a ticket? | |
| Comment by Jeffrey Yemin [ 10/Jun/14 ] | |
|
In the general case I don't think this can be done properly. Since Document is a Map<String, Object> we can't know for sure that every value in the Map is deep-copyable. That said, we are working on a new class called BsonDocument that has a closed type system of Map<String, BsonValue>. This class could easily support a deep copy via constructor:
| |
| Comment by Ross Lawley [ 09/May/14 ] | |
| Comment by Adam Brightwell [ 20/Aug/13 ] | |
|
From my testing and inspection of the code, it would appear that this method and functionality is already available in both BasicDBObject and BasicDBList as of 7a3a2364. It would appear that this is a "deep copy"? |