How to get the size of BsonDocument in C# (Other that using ToBson().Length)

786 views
Skip to first unread message

Sherry Ummen

unread,
Jul 4, 2014, 5:19:23 AM7/4/14
to mongod...@googlegroups.com

Robert Stam

unread,
Jul 5, 2014, 1:15:21 PM7/5/14
to mongod...@googlegroups.com
ToBson().Length is the only way to get the length of a BsonDocument.(where by length we mean the number of bytes that the BsonDocument requires when converted to a binary BSON stream).

You could write a function that calculated the length of a BsonDocument, but it would have to do almost as much work as ToBson anyway.

But the easiest is to just use ToBson().Length.


On Fri, Jul 4, 2014 at 5:19 AM, Sherry Ummen <sherry...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d86bd0fb-31b1-4650-a796-7f381785e093%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sherry Ummen

unread,
Jul 7, 2014, 1:33:49 AM7/7/14
to mongod...@googlegroups.com
OK hmm, why I asked this is that I was trying to dump POCO's converted as JSON object to mongodb and there are some objects which are more than 25mb. Now I am not sure what should be a good approach on this. I know there is something called GridFS but then I need to detect in the middle of storing whether the object is large object then copy to gridfs and and then querying the documents i should know whether that document is in gridfs or in normal db.

Could you please suggest what would be a good approach in this case since in my case there is high possibility of having large POCO object and I am not finding a good way to avoid this checking of the size of objects always.

Robert Stam

unread,
Jul 14, 2014, 11:20:15 AM7/14/14
to mongod...@googlegroups.com
One problem with storing large documents using GridFS is that they will be stored as binary BLOBs which means you won't be able to query them based on their contents.

Usually when one has very large documents there are just a few large fields (like images). Perhaps you could factor those out into GridFs and keep the rest of the document as a regular document.


Sherry Ummen

unread,
Jul 14, 2014, 11:38:39 AM7/14/14
to mongod...@googlegroups.com
But in my case the problem is that its just large JSON object (yeah lots of data)...right now I am splitting the document to small json objects and storing it. But then hmmm its a bit of over work of splitting it and storing it using bulk operation. So was wondering since you are a mongodb employee you may be knowing some better magical thing in mongodb :)

Asya Kamsky

unread,
Jul 15, 2014, 12:44:05 AM7/15/14
to mongodb-user
What kind of data is in this JSON document that it's so large?  In general you have an option of storing associated information in a single document or in multiple documents and storing in a single document usually will lead to some limitations in how you can query/update them, etc.

Asya



Sherry Ummen

unread,
Jul 15, 2014, 12:45:39 AM7/15/14
to mongod...@googlegroups.com
Its actually Ship related data. Which would become really huge depending on the ship structure.
Reply all
Reply to author
Forward
0 new messages