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
6
votes
3 answers

What is the easiest way to convert JSON into BSON in .net world

I just started working on MongoDB. From my JavaScript client I am sending a JSON string to ASP.NET WEB API project. Is it possible to use this JSON string directly and save it into MongoDB? I also want to know whether this approach make sense ? I…
SharpCoder
  • 18,279
  • 43
  • 153
  • 249
6
votes
3 answers

Golang BSON conversion

I am trying to convert a working mongo query to bson in golang. I have the basic stuff down and working but am struggling to figure out how to integrate more advanced or queries into the mix. Anyone have a minute to help me convert the following…
Mark Hayden
  • 515
  • 4
  • 13
6
votes
1 answer

Converting BSON Type ObjectId to JSON (Storing in Mongodb) -Java

new Gson().toJson(new ObjectId()) When I do the above, the output I get is "_id" : { "_time" : 1374347520 , "_machine" : -1025067326 , "_inc" : 585905201 , "_new" : false} But Actually I want it to be as…
6
votes
1 answer

MongoDB add array to BsonDocument

I am trying to add fields in a mongodb document using C# drivers. I am creating a document. BsonDocument document = new BsonDocument(); and adding document.Add(name, value); // here name and value both are string but I am not sure how to add an…
Sameer Rathoud
  • 133
  • 3
  • 8
6
votes
2 answers

mongodb part of objectid most likely to be unique

In my app I'm letting mongo generate order id's via its ObjectId method. But in user testing we've had some concerns that the order id's are humanly 'intimidating', i.e. if you need to discuss your order with someone over the telephone, reading out…
Petrov
  • 4,200
  • 6
  • 40
  • 61
6
votes
2 answers

Unable to install bson_ext 1.8.2 gem

I am unable to install the bson_ext 1.8.2 gem in my mongo project directory. In specific I tried running bundle install and gem install bson_ext -v '1.8.2' I tried other solutions present on the forum but in vain. Installing bson_ext (1.8.2)…
jayanth pk
  • 61
  • 1
  • 3
6
votes
1 answer

Converting Python class object instance to mongodb BSON string

Does anyone know of a Python library that can convert a class object to a mongodb BSON string? Currently my only solution is to convert the class object to JSON and then JSON to BSON.
S-K'
  • 3,188
  • 8
  • 37
  • 50
6
votes
0 answers

JRuby + Warbler: jar file blows up whenever the bson gem is required

I think I may have found a bug in Warbler, but I wanted to post this here as a question in case there's something I'm doing wrong. In a nutshell, any attempt to take a jruby app that requires the 'bson' gem an package it into a .jar file with…
Jon Stokes
  • 213
  • 2
  • 7
6
votes
1 answer

MongoDB: BSON to JSON

I'm using the native mongoDB driver for node.js. I'd like to get some data from the database and send it as a JSON string via HTTP. Is there a way to convert the BSON to JSON or directly retrieve the data as JSON from the database? Thanks!
johnny
  • 8,696
  • 6
  • 25
  • 36
6
votes
2 answers

MongoDB + Ruby. How to access document properties?

I want to try Mongo with Ruby. I connected, selected collection and I can query data from MongoDB. irb(main):049:0> coll.find_one({:x=>4}) => #BSON::ObjectId('4f8ae4d7c0111ba6383cbe1b'), "x"=>4.0,…
nkuhta
  • 10,388
  • 12
  • 41
  • 54
5
votes
2 answers

Is it possible to change ASP.NET MVC 3 route constraints such that they return 400 Bad Request with JSON bodies?

I am developing some REST resources using the ASP.NET MVC 3 platform. So far, its been great, I love the flexibility of MVC 3, and it is a breeze to build REST services with it. One area where I have been having a difficult time are the route…
jrista
  • 32,447
  • 15
  • 90
  • 130
5
votes
1 answer

binary-to-text encoding, non-printing characters, protocol buffers, mongodb and bson

I have a candidate key (mongodb candidate key, __id) thats looks like the following in protocol buffers : message qrs_signature { required uint32 region_id = 1; repeated fixed32 urls = 2; }; Naturally I can't use a protocol buffers encoded…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
5
votes
2 answers

What is the syntax for Dates in MongoDB running on MongoLab?

Instead of ObjectId('82he921he982he82') its "_id":{"$oid":"82he921he982he82"} for object Ids, but I have no idea how to create a date value in a document on MongoLab :s
SomethingOn
  • 9,813
  • 17
  • 68
  • 107
5
votes
5 answers

../@types/mongodb/index.d.ts:35:18 - error TS2724: '"bson"' has no exported member named 'ObjectID'. Did you mean 'ObjectId'?

Getting this error. my typescript version is 4.5.4 and "@types/mongodb": "~3.3.1", "@types/mongoose": "~5.5.17". any idea how to solve ../@types/mongodb/index.d.ts:49:74 - error TS2724: '"bson"' has no exported member named 'ObjectID'. Did you mean…
Somesh Paradkar
  • 141
  • 1
  • 4
5
votes
2 answers

Nodejs - how compile bson parser?

Every time I try to do anything in Nodejs, what is connected with mangodb or sockets, then I receive error: node.js:134 throw e; // process.nextTick error, or 'error' event on first tick ^ Native bson parser not compiled, please…
mrok
  • 2,680
  • 3
  • 27
  • 46