Database Reference
In-Depth Information
Or you can insert the data while using line breaks, as before. For example, you can expand the preceding example by
adding an array of tracks to it. Pay close attention to how the commas and brackets are used in the following example:
> db.media.insert( { "Type" : "CD",
..."Artist" : "Nirvana",
..."Title" : "Nevermind",
... "Tracklist" : [
... {
... "Track" : "1",
... "Title" : "Smells Like Teen Spirit",
... "Length" : "5:02"
... },
... {
... "Track" : "2",
... "Title" : "In Bloom",
... "Length" : "4:15"
... }
... ]
...}
... )
As you can see, inserting data through the Mongo shell is straightforward.
The process of inserting data is extremely flexible, but you must adhere to some rules when doing so. For example,
the names of the keys while inserting documents have the following limitations:
$ character must not be the first character in the key name. Example: $tags
The
. ] character must not appear anywhere in the key name. Example: ta.gs
The period [
_id is reserved for use as a primary key ID; although it is not recommended, it can
store anything unique as a value, such as a string or an integer.
The name
Similarly, some restrictions apply when creating a collection. For example, the name of a collection must adhere
to the following rules:
The collection's name cannot exceed 128 characters.
An empty string (“ ”) cannot be used as a collection name.
The collection's name must start with either a letter or an underscore.
system is reserved for MongoDB and cannot be used.
The collection name
The collection's name cannot contain the “\0” null character.
Querying for Data
You've seen how to switch to your database and how to insert data; next, you will learn how to query for data in your
collection. Let's build on the preceding example and look at all the possible ways to get a good clear view of your data
in a given collection.
When querying your data, you have an extraordinary range of options, operators, expressions, filters, and so on
available to you. We will spend the next few sections reviewing these options.
Note
 
 
Search WWH ::




Custom Search