MongoDB stores data records as BSON documents. BSON is a binary representation of JSON documents.
{
field1: value1,
field2: value2,
field3: value3,
...
fieldN: valueN
}
The value of a field can be any of the BSON data types, including other documents, arrays, and arrays of documents. For example, the following document contains values of varying types:
var mydoc = {
_id: ObjectId("5099803df3f4948bd2f98391"),
name: { first: "Alan", last: "Turing" },
birth: new Date('Jun 23, 1912'),
death: new Date('Jun 07, 1954'),
contribs: [ "Turing machine", "Turing test", "Turingery" ],
views : NumberLong(1250000)
}
The above fields have the following data types:
_id
holds an ObjectId.name
holds an embedded document that contains the fields first
and last
.birth
and death
hold values of the Date type.contribs
holds an array of strings.views
holds a value of the NumberLong type.