Databases Reference
In-Depth Information
This example is a good illustration of several important concepts:
• Key/value pairs in documents are ordered—the earlier document is distinct from
the following document:
{"foo" : 3, "greeting" : "Hello, world!"}
In most cases the ordering of keys in documents is not important.
In fact, in some programming languages the default representation
of a document does not even maintain ordering (e.g., dictionaries
in Python and hashes in Perl or Ruby 1.8). Drivers for those lan-
guages usually have some mechanism for specifying documents
with ordering for the rare cases when it is necessary. (Those cases
will be noted throughout the text.)
• Values in documents are not just “blobs.” They can be one of several different data
types (or even an entire embedded document—see “Embedded Docu-
ments” on page 20 ). In this example the value for "greeting" is a string, whereas
the value for "foo" is an integer.
The keys in a document are strings. Any UTF-8 character is allowed in a key, with a
few notable exceptions:
• Keys must not contain the character \0 (the null character). This character is used
to signify the end of a key.
• The . and $ characters have some special properties and should be used only in
certain circumstances, as described in later chapters. In general, they should be
considered reserved, and drivers will complain if they are used inappropriately.
• Keys starting with _ should be considered reserved; although this is not strictly
enforced.
MongoDB is type-sensitive and case-sensitive. For example, these documents are
distinct:
{"foo" : 3}
{"foo" : "3"}
As are as these:
{"foo" : 3}
{"Foo" : 3}
A final important thing to note is that documents in MongoDB cannot contain duplicate
keys. For example, the following is not a legal document:
{"greeting" : "Hello, world!", "greeting" : "Hello, MongoDB!"}
 
Search WWH ::




Custom Search