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
294
votes
4 answers

How to query nested objects?

I have a problem when querying mongoDB with nested objects notation: db.messages.find( { headers : { From: "reservations@marriott.com" } } ).count() 0 db.messages.find( { 'headers.From': "reservations@marriott.com" } ).count() 5 I can't see what I…
Edmondo
  • 19,559
  • 13
  • 62
  • 115
239
votes
11 answers

Date query with ISODate in mongodb doesn't seem to work

I don't seem to be able to get even the most basic date query to work in MongoDB. With a document that looks something like this: { "_id" : "foobar/201310", "ap" : "foobar", "dt" : ISODate("2013-10-01T00:00:00.000Z"), "tl" :…
Jason Polites
  • 5,571
  • 3
  • 25
  • 24
202
votes
7 answers

What is BSON and exactly how is it different from JSON?

I am just starting out with MongoDB and one of the things that I have noticed is that it uses BSON to store data internally. However the documentation is not exactly clear on what BSON is and how it is used in MongoDB. Can someone explain it to me,…
Akshat Jiwan Sharma
  • 15,430
  • 13
  • 50
  • 60
168
votes
7 answers

Understanding MongoDB BSON Document size limit

From MongoDB The Definitive Guide: Documents larger than 4MB (when converted to BSON) cannot be saved to the database. This is a somewhat arbitrary limit (and may be raised in the future); it is mostly to prevent bad schema design and ensure …
0xdeadbeef
  • 4,090
  • 8
  • 33
  • 37
155
votes
6 answers

Performant Entity Serialization: BSON vs MessagePack (vs JSON)

Recently I've found MessagePack, an alternative binary serialization format to Google's Protocol Buffers and JSON which also outperforms both. Also there's the BSON serialization format that is used by MongoDB for storing data. Can somebody…
Alex
  • 8,245
  • 8
  • 46
  • 55
96
votes
4 answers

Protocol Buffers versus JSON or BSON

Does anyone have any information on the performance characteristics of Protocol Buffers versus BSON (binary JSON) or versus JSON in general? Wire size Serialization speed Deserialization speed These seem like good binary protocols for use over…
Jeff Meatball Yang
  • 37,839
  • 27
  • 91
  • 125
62
votes
9 answers

Creating BSON object from JSON string

I have Java app that takes data from external app. Incoming JSONs are in Strings. I would like to parse that Strings and create BSON objects. Unfortunate I can't find API for that in Java's BSON implementation. Do I have use external parser for that…
Maciek Sawicki
  • 6,717
  • 9
  • 34
  • 48
52
votes
5 answers

Force mongodb to output strict JSON

I want to consume the raw output of some MongoDB commands in other programs that speak JSON. When I run commands in the mongo shell, they represent Extended JSON, fields in "shell mode", with special fields like NumberLong , Date, and Timestamp. I…
whereswalden
  • 4,819
  • 3
  • 27
  • 41
47
votes
3 answers

How to convert BSON to JSON with human-readable date format

I would like to transform a BSON dump of MongoDB to JSON. To do that, I'm using the bsondump tool provided with Mongo, but I get an output like : { "_id" : ObjectId( "5316d194b34f6a0c8776e187" ), "begin_date" : Date( 1394004372038 ), "foo" : "bar"…
vcarel
  • 1,787
  • 1
  • 16
  • 23
43
votes
7 answers

MongoDB - What about Decimal type of value?

I am currently learning and applying MongoDB for a small financial related project. When I read MongoDB in Action, it says: The only other issue that commonly arises with BSON numeric types is the lack of decimal support. This means that if you’re…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
41
votes
1 answer

Compare JSON and BSON

I am comparing JSON and BSON for serializing objects. These objects contain several arrays of a large number of integers. In my test the object I am serializing contains a total number of about 12,000 integers. I am only interested in how the sizes…
Ronald
  • 657
  • 1
  • 6
  • 13
40
votes
2 answers

Which one is lighter, JSON or BSON?

I have written code to serialize objects to JSON and BSON. According to my output, the BSON produced is greater in size than the JSON. Is this expected? From my code for Bson.class (using Jackson and bson4jackson) private ByteArrayOutputStream baos…
Auf
  • 473
  • 2
  • 5
  • 9
38
votes
4 answers

MongoDB Structure for message app

I am breaking my mind up thinking about a good document structure for handling a message app. I basically need three (or four) types of objects: The user (username, email, password, etc.) The contacts list (containing different contacts or contacts…
dev.pus
  • 7,919
  • 13
  • 37
  • 51
32
votes
1 answer

mongodb c# how to work with BSON document

I've spent MANY hours looking for the answer... This is very easy in PHP but I just can't put it together in C#(I'm new to C# and mongo...) I'm trying to iterate through all levels of a stored document. The document looks like this: { "_id":…
user2167261
  • 325
  • 1
  • 4
  • 7
29
votes
3 answers

import pymongo causes `ImportError: cannot import name BSON`. how do you fix the import error?

I'm having trouble getting a simple Hello World app to work using Flask, MongoDB, and Python. The app is bombing when trying to import from the bson module. All modules were installed successfully via pip and I'm running in a virtualenv, so I'm not…
Wesley Tansey
  • 4,555
  • 10
  • 42
  • 69
1
2 3
93 94