Database Reference
In-Depth Information
},
{
productID
:
“9781935504511”
,
orderLineQuantity
:
3
},
{
productID
:
“9781935504535”
,
orderLineQuantity
:
2
} ] }
Notice that a field value is not limited to just a simple value such as
4839-02,
but can also
include arrays that can contain many other fields and even documents, as we see in this
example with
orderLine
. MongoDB provides robust capability for querying within arrays.
Every database has certain restrictions on naming fields, and MongoDB is no exception.
Here are several tips in naming MongoDB fields:
•
Avoid special characters. Characters such as a period, dollar sign, or null (\0)
should be avoided in field names.
•
MongoDB is case sensitive.
CustomerLastName
and
customerLastName
are
distinct fields. Make sure your organization has a naming standard so you use case
consistently.
•
Duplicate names are not allowed. The same document cannot contain two or more
of the same field names at the same level of depth. Just like a relational database
table cannot contain the element
customerLastName
twice, a MongoDB docu-
ment cannot contain the same field twice at the same level of depth. You can,
however, have the same field name at a different level of depth. For example, al-
though
{ customerLastName : “Smith”, customerLastName : “Jones” }
is not allowed,
{ customer-
LastName : { customerLastName : “Jones” } }
is allowed.
D
OMAINS
The complete set of all possible values that an attribute contains is called a domain. An
attribute can never contain values outside of its assigned domain, which is defined by spe-
cifying the actual list of values or a set of rules.
Employee Gender Code
, for example, can
be limited to the domain of (
female
,
male
).
In relational databases, there are three main types of domains: