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
5
votes
1 answer

Access just the value of BSON::ObjectId in ruby

I'm working on a ruby/rails app backed by Mongodb (using Mongoid). Within the context of the Rails application everything works flawlessly but we're also accessing objects outside of the Rails environment, where I'm having trouble getting the id of…
Jay Stakelon
  • 88
  • 2
  • 7
5
votes
3 answers

Export from MongoDB Cloud into local MongoDB ("$oid is not valid for storage." error)

I'm just learning about MongoDB. Is there an easy way to export/import data from MongoDB? The task at hand is simple: Using MongoDB Cloud, copy a document from a collection (using the Copy Document button located in the Atlas > Collection section)…
Metafaniel
  • 29,318
  • 8
  • 40
  • 67
5
votes
2 answers

How can I stringify a BSON object inside of a MongoDB map function?

I have documents with field xyz containing { term: "puppies", page: { skip: 1, per_page: 20 } } // not useful as a composite key... { page: { skip: 1, per_page: 20 }, term: "puppies" } // different order, same contents For the sake of determining…
Seamus Abshere
  • 8,326
  • 4
  • 44
  • 61
5
votes
1 answer

How do I deserialize output from mongo-go-driver as bson array into a []interface{} when primitive.A is bson []interface

I have a map[string]interface{} that generated from a mongo query that is using the new mongo-go-driver I want to process certain values in the map and replace the £ characters in the values belonging to the aggregate key Here is the map: result2 =…
5
votes
1 answer

NodeJS best way to store a file-based JSON database?

I've seen many similar questions, but nonecan address my particular inquiry: I want to have my own JSON based database, similar to how MongoDB and firebase have BSON databases', and I figured the simplest way to do that is just to: store some JSON…
Yaakov5777
  • 309
  • 5
  • 15
5
votes
0 answers

How is JSON a BINARY encoding format?

According to the book Designing Data Intensive Applications, it says whenever you want to send data over the network or write it to a file—you need to encode it as a sequence of bytes. It then goes on to introduce JSON, XML as human readable…
user1008636
  • 2,989
  • 11
  • 31
  • 45
5
votes
2 answers

Can't get mongodb record by ObjectId in golang

I'm try to get mongodb record by ObjectId by using following code, but keep getting not found by err.Error() Following is my mongo collection sample { "_id" : ObjectId("5a2a75f777e864d018131a59"), "callDate" : "22/12/2017", "time" : "16.25",…
Nisal Edu
  • 7,237
  • 4
  • 28
  • 34
5
votes
1 answer

Does Key order matter in a MongoDB BSON doc?

I know certain commends need the hashmap / dictionary to be ordered, but does the actual BSON document in MongoDB matter and would the index still work? E.g. db.people.ensureIndex({LName:1, FName:1}); Would it work on both: {LName:"abc",…
Henry
  • 32,689
  • 19
  • 120
  • 221
5
votes
1 answer

How would you store a number larger than the max 64 bit int in mongoDb?

The number is larger than 9223372036854775807 - too big for NumberLong, which is mongo's native 64-bit long type. What's the best way to do this/the best field type? Is it possible to preserve any of the querying functionality of a smaller…
Sawyer
  • 221
  • 3
  • 6
5
votes
5 answers

MongoDB "NumberLong/$numberLong" issue while converting back to Java Object

I am having a json which is somethink like {"Header" : {"name" : "TestData", "contactNumber" : 8019071740}} If i insert this to mongoDB it will be something like {"_id" : ObjectId("58b7e55097989619e4ddb0bb"),"Header" : {"name" :…
Geek
  • 1,214
  • 5
  • 14
  • 27
5
votes
1 answer

Use MongoDB _id field as composite field with multiple fields

Since every collection in mongodb has a default index on the _id column, I wanted to leverage it for my scenario as below. I have my collection as below, { "_id":{ "timestamp" : ISODate("2016-08-24T23:22:20.201Z"), …
javauser
  • 91
  • 4
  • 11
5
votes
1 answer

Deserialize json generated by mongodb that contains bson datatypes

I received a few JSON data files- however, it has the BSON datatypes included in each object; on top of that, its a really large tojson dump (millions of records). I am trying to deserialize the data and as expected it fails. The JSON file has…
zxed
  • 336
  • 2
  • 12
5
votes
1 answer

Can you change a bsoncxx object (document/value/element)?

I'm using the mongocxx driver and I am considering keeping the query results given in BSON as a data holder in a couple of objects instead of parsing the BSON to retrieve the values and then discard it. This would make some sense "if" I can edit the…
André Moreira
  • 1,669
  • 4
  • 21
  • 35
5
votes
2 answers

laravel mongodb closing client connection remaining data too small

Route::get('/', function () { $tweets = Tweet::all(); return view('welcome', ['tweets' => $tweets]); }); I am making a laravel app using mongodb. When I go to '/', I get an error in the mongod terminal that says AssertionException…
5
votes
2 answers

Python, Convert bson output of mongodump to array of json objects (dictionaries)

I have dumped a mongodb collection using the mongodump command. The output is a dump directory which has these files: dump/ |___coll.bson |___coll.metadata.json How can I open the exported files to a array of dictionaries that work in…
CentAu
  • 10,660
  • 15
  • 59
  • 85