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
8
votes
0 answers

Converting the org.bson.Document to Java class object

I am using Mongo driver for java 3.2.2 and trying to convert the bson document to valid java object. When I am using the below java code : Document value = (Document)dataObject.get(VALUE); Gson gson = new Gson(); CustomClasss classObject =…
Amandeep Singh
  • 3,754
  • 8
  • 51
  • 72
8
votes
1 answer

Parse bson string in python?

I have a bson formatted string in file I want to read that file and get the encoded json. I was looking into the example here: >>> from bson import BSON >>> bson_string = BSON.encode({"hello": "world"}) >>>…
frazman
  • 32,081
  • 75
  • 184
  • 269
8
votes
1 answer

MongoDB can't update document because _id is string, not ObjectId

I'm doing a rest api to exchange data between a mongo database and a web app. These data are json formatted. I have a trouble when it comes to update a document: cannot change _id of a document. As a matter of fact, in my JSON the _id of the doc…
t4ncr3d3
  • 615
  • 1
  • 8
  • 17
7
votes
2 answers

Bson library for Delphi?

Can someone suggest a complete Bson library for Delphi ? I'm trying to use http://code.google.com/p/pebongo/source/browse/trunk/_bson.pas from http://bsonspec.org, but there are some structures that aren't supported. Or maybe I'm not using it…
Rodrigo Farias Rezino
  • 2,687
  • 3
  • 33
  • 60
7
votes
4 answers

bson.errors.InvalidDocument: key '$numberDecimal' must not start with '$' when using json

I have a small json file, with the following lines: { "IdTitulo": "Jaws", "IdDirector": "Steven Spielberg", "IdNumber": 8, "IdDecimal": "2.33" } An there is a schema in my db collection, named test_dec. This is what I've used to…
powerPixie
  • 718
  • 9
  • 20
7
votes
1 answer

How to add values to an bson.D object

I'm working with golang and the MongoDB driver, I want to patch one of my objects according to the data I get from the outside: I have a struct: type Pivot struct { Email string `json:"email"` Base string …
hestellezg
  • 3,309
  • 3
  • 33
  • 37
7
votes
1 answer

Mongodb dump (filtering documents and fields)

I want to make a partial dump of a Mongodb database (partial as in, I need to filter some documents and some fields). Then, this dump will be imported onto another server. I cannot use the mongodump utility, as it doesn't allow filtering fields. I…
MikiTesi
  • 181
  • 1
  • 2
  • 7
7
votes
1 answer

Python bson: How to create list of ObjectIds in a New Column

I have a CSV that I'm needing to create a column of random unique MongoDB ids in python. Here's my csv file: import pandas as pd df = pd.read_csv('file.csv', sep=';') print(df) Zone Zone_1 Zone_2 I'm currently…
mm_nieder
  • 431
  • 1
  • 4
  • 10
7
votes
5 answers

Serialize get-only properties on MongoDb

With C# 6 I can write: public class Person { public Guid Id { get; } public string Name { get; } public Person(Guid id, string name) { Id = id; Name = name; } } Unfortunately a class like this is not serialized…
Davide Icardi
  • 11,919
  • 8
  • 56
  • 77
7
votes
1 answer

Why does Meteor use EJSON and not BSON directly?

As I understand it, Node.js supports BSON (not sure if natively or with an npm package). Meteor however invented a new flavor EJSON (Enhanced JSON), but I fail to see what advantages this brings and how it is better than using BSON directly. Does…
Stephan
  • 1,279
  • 8
  • 16
7
votes
3 answers

Ignore a property when saving a POCO in MongoDB, but not ignoring it when serializing to JSON

I have the following model that I'm storing in MongoDB: public class Person { public ObjectId Id { get; set; } public Int PersonId { get; set; } public BsonDocument Resume { get; set; } // arbitrary JSON [BsonIgnore] public…
Chad Levy
  • 10,032
  • 7
  • 41
  • 69
7
votes
5 answers

Setting default MongoDb/Bson representation for all decimals to double

I am helping to write a C# application to analyse financial data. Internally all the numbers are stored as decimal, however when we persist them to our mongodb database, we would like them to be stored as doubles, rather than strings. I know I can…
Nikki Locke
  • 2,759
  • 6
  • 29
  • 53
7
votes
2 answers

How can I make RestSharp use BSON?

I'm using RestSharp, and using Json.NET for serialization (see here). Json.NET supports BSON, and since some of my requests have huge blocks of binary data, I think this would speed up my application dramatically. However, as far as I can tell,…
Gary McGill
  • 26,400
  • 25
  • 118
  • 202
7
votes
2 answers

Ruby: Binary String to IO

I have a string of binary data and I need it as an IO object. So I tried this: r, w = IO.pipe() w << data But it fails with this error: Encoding::UndefinedConversionError ("\xD0" from ASCII-8BIT to UTF-8) Why is it trying to convert to UTF-8 in…
Rotem Harel
  • 736
  • 8
  • 16
7
votes
1 answer

Encoding custom python objects as BSON with pymongo

Is there a way to tell pymongo to use a custom encoder to convert python objects to BSON? Specifically I need to convert numpy arrays into BSON. I know I can manually ensure every numpy array gets converted to a native python array before sending…
Leopd
  • 41,333
  • 31
  • 129
  • 167