sample output with type debug
bsondump --pretty --type=debug audit.bson.2017-03-10T10-38-23
--- new object ---
size : 236
atype
type: 2 size: 28
ts
type: 9 size: 12
local
type: 3 size: 37
--- new object ---
size : 30
ip
type: 2 size: 15
port
type: 16 size: 10
remote
type: 3 size: 38
--- new object ---
size : 30
ip
type: 2 size: 15
port
type: 16 size: 10
users
type: 4 size: 53
--- new object ---
size : 46
0
type: 3 size: 41
--- new object ---
size : 38
user
type: 2 size: 19
db
type: 2 size: 14
roles
type: 4 size: 12
--- new object ---
size : 5
param
type: 3 size: 39
--- new object ---
size : 32
ns
type: 2 size: 27
result
type: 16 size: 12
--- new object ---
What's --- new object ---
? It seems not to be a JSON document.
What's type
and the number? Is size
characters or other measurement?
Why this output is useful? What's the usecase for DBA or App developer?
Best Answer
The
bsondump
utility converts BSON data (which is binary) into human-readable formats. Common usage would bebsondump --pretty
to inspect data formatted as MongoDB Extended JSON. This can be useful for previewing data contained in BSON files as created bymongodump
, replica set rollbacks, and other features (eg. auditing in MongoDB Enterprise as per your example).The
--type=debug
output is generally only relevant for a developer who wants to see an annotated view of the BSON (as per the BSON spec).This indicates the start of a new BSON object, which would be represented as an opening curly brace (
{
) in JSON. You will see this at the top level for each new document and for every embedded document/array.This indicates the BSON type and size (in bytes) of that object including nested fields/objects.
Potential use cases for confirming underlying data types might be checking for consistency (eg. a given field has the expected type) or confirming underlying data types in order to do a query using the
$type
operator in MongoDB.You can perform a similar size calculation for a document/object in the
mongo
shell usingObject.bsonsize(object)
.