Understanding MongoDB Documents: Fields & Data Types

The document, which is comprised of field/value pairs, is at the heart of the MongoDB data structure. Most interactions with MongoDB occur at the document level.

field can contain a single value, multiple fields, or multiple elements.

A value made up of multiple fields is referred to as an embedded document and is assigned the Object data type (see field cars in the screenshot). When rendered in the JSON format, an embedded document is enclosed in curly braces and adheres to the same structure as the outer (main) document.

A value made up of multiple elements is referred to as an array and is assigned the Array data type (see field Profession in the screenshot). When rendered in the JSON format, an array is enclosed in square brackets, with each element separated by a comma. An element can be a scalar value (like in the field Profession) or an embedded document (like in the field cars).

MongoDB Data Types

A field can be one of these MongoDB data types:

Binary data“binData”
Regular Expression“regex”
JavaScript (with scope)“javascriptWithScope”
32-bit integer“int”
64-bit integer“long”
Min key“minKey”
Max key“maxKey”

Not surprisingly, there’s much more to the document data structure than what is covered here. For more in-depth information, see the topics Databases and Collections and Documents in the MongoDB manual.

Terms you might not know:

data type: an attribute that tells what kind of data that value can have. Common data types include: integers, strings, floating point values (source)

embedded document: related data attached in a single structure or document (source)

scalar value: a variable that holds one value at a time. It is a single component that assumes a range of number or string values (source)

Log in

Log in to your Studio 3T Academy account

Forgot password?

Don't have an account yet? Sign up
Sign up

Start learning MongoDB today. All fields are mandatory.

By signing up for a course, you agree to the 3T Software Labs Privacy Policy.

Already have an account? Log in