[JAVA-429] Allow DBCollections to be modified using raw/binary BSON. Created: 02/Sep/11  Updated: 14/May/14  Resolved: 15/May/12

Status: Closed
Project: Java Driver
Component/s: API, Performance
Affects Version/s: 2.6.5
Fix Version/s: 2.8.0

Type: New Feature Priority: Major - P3
Reporter: Marko Assignee: Jeffrey Yemin
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change

 Description   

For any case where DBCollection takes a DBObject i would like to be able to pass raw/binary BSON, rather than build a concrete DBObject object such as BasicDBObject.

For my usecase i need to serialize DBObjects offline before i eventually update/insert them into DBCollection.

So rather than serialize offline, then deserialize, then build a DBObject, then call DBCollection, which then serializes the DBObject to BSON for transport over-the-wire to the Mongodb, i would rather serialize offline directly to binary BSON, then pass the BSON directly to DBCollection.

It appears that RawDBObject is exactly what i need, but there is no public constructor and no usage doc or any tests that i can see?



 Comments   
Comment by Jeffrey Yemin [ 18/Jun/12 ]

Closing for 2.8.0 release.

Comment by Jeffrey Yemin [ 15/May/12 ]

You can do this with com.mongodb.LazyDBObject. See com.mongodb.LazyDBObjectTest#testLazyDBEncoder unit test for an example of usage. This will be in 2.8.0.

Comment by Marko [ 06/Sep/11 ]

Awesome. Any idea what version these changes might be targeted for?

Thanks for your consideration Scott.

Comment by Scott Hernandez (Inactive) [ 06/Sep/11 ]

Yes, marko, that could be an option.

The Lazy* code is still under active dev, but what you have described would be part of the goal for encoding it back to a bson stream.

Comment by Marko [ 06/Sep/11 ]

Was looking a little closer at the source.

If i'm following the code correctly, it seems that OutMessage is ultimately responsible for streaming the requested BSONObject to the DBCollection. But there does not seem to be anything in the API that currently allows the OutMessage to directly send an internal binary encoding of a BSONObject? It always seems to stream the BSONObject by recursing through each field.

Maybe a new serialization interface could be created that BSONObjects could optionally implement that allow the BSONObject to take responsibility for the serialization? Implements such as LazyBSONObject could then implement the interface, exposing a very efficient way to serialize it's internal binary encoding (basically just directly writing it's internal buffer).

Then maybe for my usecase i could then use BSONEncoder to serialize offline, then i would deserialize using the LazyBSONDecoder, and use that result to efficiently write to the DBCollection.

Generated at Thu Feb 08 08:52:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.