Does anyone known of a simple utility for editing a simple BSON database/file?
Asked
Active
Viewed 2.2k times
14
-
1i'd also be interested in this.... – Alex Apr 24 '12 at 16:29
-
1This would be very convenient for peeking into backups – Jared Martin Nov 15 '14 at 18:52
2 Answers
10
The installation package that includes mongodump
('mongo-tools' on Ubuntu) should also include bsondump
, for which the manpage says:
bsondump - examine BSON files in a human-readable form
You can convert BSON to JSON with the following:
bsondump --pretty <your_file.bson
As a data interchange format, BSON may not be suitable for editing directly. For manipulating a BSON dataset, you could, of course, upload it to MonogDB and work with that. Or, you could open the bsondump
decoded JSON in an editor. But the BSON Wikipedia article indicates that compatible libraries exist in several languages, which suggests that you should also be able to decode it programmatically to an internal map representation and edit that internal representation in code.

Brent Bradburn
- 51,587
- 17
- 154
- 173
-
For further options/alternatives, see also [What is difference between mongodump and mongoexport?](https://dba.stackexchange.com/q/194370/186897) + [mongodump vs mongoexport: which is better?](https://stackoverflow.com/questions/63719882/mongodump-vs-mongoexport-which-is-better) and the possibility of using [`mongoimport`](https://www.mongodb.com/docs/database-tools/) to import JSON-formatted data (after `bsondump`), but beware the [caveat about type fidelity](https://www.mongodb.com/docs/v4.2/reference/program/mongoexport/#type-fidelity). – Brent Bradburn Aug 30 '22 at 16:00
-
BSON is produced with `mongodump`, as described at [How to export all collections in MongoDB?](https://stackoverflow.com/q/11255630/86967), with 'snapshot' error addressed with `--forceTableScan` as described at [Mongodump: Unrecognized field 'snapshot'](https://dba.stackexchange.com/q/215534/186897). – Brent Bradburn Aug 30 '22 at 16:06
-
Find the BSON specification and list of implementations here: https://bsonspec.org/ – Brent Bradburn Jun 26 '23 at 18:12