A document is a MongoDB record made of named fields and values. Documents live in collections, which live in databases. MongoDB stores them as BSON, an extension of JSON with additional data types. A field can hold a string, number, date, array, or nested document. section 2.6 section 2.6.4
Documents can keep related application data together rather than forcing it into separate tables. Their fields and types can differ within one collection, so a structure can evolve as requirements change. That flexibility still calls for deliberate schema design: consider relationships, query patterns, and likely changes when deciding what belongs in a document. section 1.1 section 5.0
Inspect a document
In mongosh, select the sample database with `use sample_training`, then run `db.grades.findOne()`. The returned academic record has an `_id`, student and class identifiers, and a `scores` array whose entries contain assessment types and scores. If no top-level `_id` is supplied on insertion, MongoDB adds one using an ObjectId. section 2.6.4
Listing 2.7 Displaying a single MongoDB document using findOne()
[primary] sample_training> use sample_training
already on db sample_training
[primary] sample_training> db.grades.findOne()
{
_id: ObjectId('56d5f7eb604eb380b0d8d8ce'),
student_id: 0,
scores: [
{ type: 'exam', score: 78.40446309504266 },
{ type: 'quiz', score: 73.36224783231339 },
{ type: 'homework', score: 46.980982486720535 },
{ type: 'homework', score: 76.67556138656222 }
],
class_id: 339
}
[primary] sample_training>
The shell result shows field–value pairs and an array of embedded assessment documents in one record. section 2.6.4
A BSON document cannot exceed 16 MB; the limit prevents one record from consuming excessive memory or transmission bandwidth. Keep that boundary in mind when gathering related data into a document. section 2.6.4







