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
16
votes
2 answers

Can strict JSON $dates be used in a MongoDB query?

I'm trying to write a date comparison query using MongoDB's strict JSON representation of BSON. I'd like it to work in the MongoDB shell (v2.4.3) Here's what I've tried... Setup: create a new document with an at date of Jan 1, 2020 >…
Bosh
  • 8,138
  • 11
  • 51
  • 77
15
votes
5 answers

BSON library for java?

We have good support for JSON in java http://blog.locut.us/main/2009/10/14/which-is-the-best-java-json-library.html but what about BSON. What library do you know that provides BSON support for java? It should obviously be efficient in runtime.
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
15
votes
4 answers

How to convert MongoDB BSONDocument to valid JSON in PHP?

I am using MongoDB with the PHP Library. I inserted a valid JSON document inside MongoDB using PHP. I am now retrieving the document using findOne and am getting a MongoDB\Model\BSONDocument object as a result. How do I get back my JSON document…
sawrubh
  • 321
  • 1
  • 5
  • 14
15
votes
4 answers

Dictionary-to-BsonDocument conversion omitting _t field

I'm using ToBsonDocument extension method from MongoDB.Bson to convert this Dictionary: var dictionary = new Dictionary {{"person", new Dictionary {{"name", "John"}}}}; var document =…
vorou
  • 1,869
  • 3
  • 18
  • 35
14
votes
2 answers

Simple Editor for BSON Databases

Does anyone known of a simple utility for editing a simple BSON database/file?
Lawrence Wagerfield
  • 6,471
  • 5
  • 42
  • 84
14
votes
3 answers

Why is JSON faster than BSON in node.js?

After reading this, there is a quote that stood out: BSON is also designed to be fast to encode and decode. For example, integers are stored as 32 (or 64) bit integers, so they don't need to be parsed to and from text. This uses more space than…
NiCk Newman
  • 1,716
  • 7
  • 23
  • 48
14
votes
3 answers

Read BSON file in Python?

I want to read a BSON format Mongo dump in Python and process the data. I am using the Python bson package (which I'd prefer to use rather than have a pymongo dependency), but it doesn't explain how to read from a file. This is what I'm trying:…
Richard
  • 62,943
  • 126
  • 334
  • 542
14
votes
2 answers

What is the difference between EmbeddedDocumentField and ReferenceField in mongoengine

Internally, what are the differences between these two fields? What kind of schema do these fields map to in mongo? Also, how should documents with relations be added to these fields? For example, if I use from mongoengine import * class…
user1876508
  • 12,864
  • 21
  • 68
  • 105
13
votes
4 answers

Can MongoDB and its drivers preserve the ordering of document elements

I am considering using MongoDB to store documents that include a list of key/value pairs. The safe but ugly and bloated way to store this is as [ ['k1' : 'v1'] , ['k2' : 'v2'], ...] But document elements are inherently ordered within the…
Adrian Ratnapala
  • 5,485
  • 2
  • 29
  • 39
13
votes
5 answers

bson_ext gem install fails on macOS

I'm stuck with install bson_ext gem with 1.5.1 version. I've tried almost everything what I found on web but nothing helps. I tried to reinstall ruby, rvm and so on. I am using: RVM MacOs Catalina 10.15.6 ruby 2.6.5 and after bundle install I got…
Lukasz
  • 207
  • 2
  • 10
13
votes
1 answer

Convert BSON to valid JSON

The BsonDocument.ToJson() method returns invalid JSON, as ObjectID() and ISODate are not valid JSON. What's the best way to get valid JSON from an arbitary BSON document?
BanksySan
  • 27,362
  • 33
  • 117
  • 216
13
votes
1 answer

Handling Custom BSON Marshaling

I have a number of structs that require custom marshalling. When I was testing I was using JSON and the standard JSON marshaller. As it doesn't marshal unexported fields, I needed to write a custom MarshalJSON function, which worked perfectly. When…
leylandski
  • 448
  • 1
  • 4
  • 15
12
votes
1 answer

mongodb-go-driver/bson struct to bson.Document encoding

I'm working with https://github.com/mongodb/mongo-go-driver and currently trying to implement a partial update of such struct type NoteUpdate struct { ID string `json:"id,omitempty" bson:"_id,omitempty"` Title string `json:"title"…
12
votes
3 answers

How to send File through Websocket along with additional info?

I'm developing a Web application to send images, videos, etc. to two monitors from an admin interface. I'm using ws in Node.js for the server side. I've implemented selecting images available on the server and external URLs and sending them to the…
user2859982
  • 223
  • 1
  • 2
  • 4
12
votes
2 answers

How to check that mongo ObjectID is valid in python?

I want to verify that the objectID is a valid mongoID string. Currently I have: import bson try: bson.objectid.ObjectId(id) except: pass # do something I wanted to make my exception more specific, and it looks like there is a solution, but…
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
1 2
3
93 94