Questions tagged [bson]

BSON stands for "Binary JSON". It is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database.

BSON [bee · sahn], short for Bin­ary JSON, is a bin­ary-en­coded seri­al­iz­a­tion of JSON-like doc­u­ments. Like JSON, BSON sup­ports the em­bed­ding of doc­u­ments and ar­rays with­in oth­er doc­u­ments and ar­rays. BSON also con­tains ex­ten­sions that al­low rep­res­ent­a­tion of data types that are not part of the JSON spec. For ex­ample, BSON has a Date type and a BinData type.

BSON can be com­pared to bin­ary inter­change for­mats, like Proto­col Buf­fers. BSON is more "schema-less" than Proto­col Buf­fers, which can give it an ad­vant­age in flex­ib­il­ity but also a slight dis­ad­vant­age in space ef­fi­ciency (BSON has over­head for field names with­in the seri­al­ized data).

BSON was de­signed to have the fol­low­ing three char­ac­ter­ist­ics:

  1. Lightweight

    Keep­ing spa­tial over­head to a min­im­um is im­port­ant for any data rep­res­ent­a­tion format, es­pe­cially when used over the net­work.

  2. Traversable

    BSON is de­signed to be tra­versed eas­ily. This is a vi­tal prop­erty in its role as the primary data rep­res­ent­a­tion for Mon­goDB.

  3. Efficient

    En­cod­ing data to BSON and de­cod­ing from BSON can be per­formed very quickly in most lan­guages due to the use of C data types.

Related Links

1403 questions
7
votes
1 answer

mongodb with rails, find by id in array

I can fetch an element by BSON id from Mongodb with db.my_collection.find({_id: ObjectId("567bc95ab62c732243123450")}) And it works. But how can I get an array of ids? something like db.my_collection.find({_id:…
valk
  • 9,363
  • 12
  • 59
  • 79
6
votes
1 answer

How to convert string to BSON using MongoDB C++ driver?

Similar to toString is there a way we can convert a string to BSON object? I need to remove a document using C++ driver the the remove function expects the query to have BSON object.
user837208
  • 2,487
  • 7
  • 37
  • 54
6
votes
2 answers

Properly parse a Mongo cursor to PHP

When converting a MongoCursor to PHP I use this script. Which was presented here StackOverflowSO using the upper method, the structure is same but _id is whereas using the lower script which yields the below included result. Unfortunately, this…
user1094824
  • 175
  • 2
  • 8
6
votes
4 answers

How to get ObjectID as String from mongo-go-driver cursor?

I would like to get ObjectID as a string because I have other storage types, so I want to avoid to use primitive.ObjectID in my struct to keep the layers independent. I'm new to Golang, thanks. package listing type Card struct { ID …
Bruno Canongia
  • 514
  • 6
  • 12
6
votes
0 answers

Migration Spring Boot 1.X to 2.X remove _class field from BSON Document

I recently migrated the Spring Boot version of a project, upgrading from version 1.X to 2.X. However, this caused problems in recovering persisted objects using the org.bson.Document (using PojoCodecProvider), because they did not have the _class…
falvojr
  • 3,060
  • 4
  • 31
  • 54
6
votes
3 answers

How to ignore nulls while unmarshalling a MongoDB document?

I would like to know if there's any approach that would allow me to ignore null types while unmarshalling a MongoDB document into a Go struct. Right now I have some auto-generate Go structs, something like this: type User struct { Name string…
Andrew
  • 63
  • 1
  • 3
6
votes
1 answer

How to read and write BSON documents in Android

Dear All, Can anyone tell me that how to read and write BSON document in Android. Thanks in Advance. Irfan
Irfan
  • 61
  • 1
  • 2
6
votes
1 answer

PHP DateTime with TimeZone to MongoDB\BSON\UTCDateTime

I need help with PHP DateTime with TimeZone converting to MongoDB\BSON\UTCDateTime. If I have string "2015-10-20T04:02:00.608000+01:00" it gives me a DateTime $date = DateTime::createFromFormat( 'Y-m-d\TH:i:s.uT', $string ); DateTime date =>…
Čamo
  • 3,863
  • 13
  • 62
  • 114
6
votes
3 answers

How to flatten out a nested json structure in go

I am getting nested data from mongo and I want to flatten that out in a structure to store it in a csv file. The data looks like this: { "_id" : "bec7bfaa-7a47-4f61-a463-5966a2b5c8ce", "data" : { "driver" : { "etaToStore"…
Naguib Ihab
  • 4,259
  • 7
  • 44
  • 80
6
votes
0 answers

Store files under 16MB in MongoDB using GridFs is a good idea?

I know MongoDB documents only supports up to 16MB. If I want to store files bigger than this value, I should use GridFs. Lower than that, they suggest to use BSON instead. I have made a test, saving 33000 files with 10MB each, 16500 using BSON and…
Gabriel
  • 952
  • 10
  • 31
6
votes
2 answers

How to Convert List to BsonArray to save a MongoDB Document

I'm having an Model Class, I need to Save it in a MongoDB Collection. My Model Class: public Class Employee { public string EmpID { get; set; } public string EmpName { get; set; } public List EmpMobile { get; set; } } public…
user6060080
6
votes
2 answers

How do I generate a Mongo DB ObjectID in Swift?

I need to generate a timestamped object id of BSON format in Swift. The ObjectID is for Mongo DB. How can this be accomplished?
Andrew Johnson
  • 579
  • 4
  • 23
6
votes
1 answer

Golang Bson sort parameters in mgo

I am trying to pass a multiple sort query to the "Sort" parameter of the mgo package (see https://godoc.org/labix.org/v2/mgo#Query.Sort). If the parameters are dynamic (currently held in a slice), how can I translate that into a valid sort string. A…
Glenn Walker
  • 264
  • 1
  • 3
  • 8
6
votes
2 answers

Bson - How to convert JSON to List and List to JSON?

I'm using Java Driver 3.0 with MongoDB in order to send JSONs through a webservice. When I want to convert a Document object (org.bson.Document) to JSON, I use obj.toJson(), and when I want to convert a JSON to a Document object, I use…
Thematrixme
  • 318
  • 1
  • 4
  • 14
6
votes
0 answers

BSON::Binary::InvalidType "my file content" is not a valid binary type. Please use one of :generic, :function, :old, :uuid_old, :uuid, :md5, :user.):

I am trying to save files into gridfs using carrierwave mongoid in rails. I am unable to do this process due to this error: BSON::Binary::InvalidType ("my file content" is not a valid binary type. Please use one of :generic, :function, :old,…