Basics: MongoDB

Getting Started...

  1. A document is the basic unit of data for MongoDB = Row in RDBMS

  2. Similarly, a collection can be thought of as a table with a dynamic schema.

  3. A single instance of MongoDB can host multiple independent databases, each of which can have its own collections.

  4. Every document has a special key, "_id", = Primary Key

  5. MongoDB comes with a simple but powerful JavaScript shell.

  6. Document: an ordered set of keys with associated values. = Map or Dictionary

    key: value   
    

    Ex: {"greeting" : "Hello, world!"}

  7. IMP. 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. In general, they should be considered reserved, and drivers will complain if they are used inappropriately.

  1. MongoDB is type-sensitive and case-sensitive. For example, these documents are distinct:

{"foo" : 3} // string:num {"foo" : "3"} //string:string

as are as these:

{"foo" : 3} {"Foo" : 3}

  1. MongoDB cannot contain duplicate keys.

  2. A collection is a group of documents.