198
F. Firouzi and B. Farahani
On the other hand, NoSQL is used:
• When ACID support is not required
• When a traditional RDBMS model is insufficient
• When data being stored requires flexible schema
• When constraints or validation logic is not needed
• When logging data from distributed sources
• When storing temporary data or wish lists and session data
4.6.1.1 MongoDB
MongoDB is a document-oriented, cross-platform database that offers high performance and data availability while being easily scalable; MongoDB is able to support
diverse schema, balance loads, handle replication, indexing, queries, and filing (i.e.,
to work as a file system) [16, 18].
• Collection: A group of MongoDB documents is called a collection. Documents in
MongoDB are equivalent to tables in RDBMS. Documents housed in a collection
may contain diverse fields; however, all documents in a particular collection are
used for a similar or related purpose.
• Document: A document is known as a set of key-value pairs, often with dynamic
schema, meaning documents within the same collection are not required to have
identical fields or structures and common document fields may hold different
data. Table 4.1 illustrates the relationship between RDBMS terminology and
MongoDB. Figure 4.15 also shows the MongoDB document structure of a blog
site using a comma-separated key-value pair.
• Relationship: In MongoDB, relationships illustrate how different documents
are logically connected to each other. Unfortunately, MongoDB cannot support
traditional primary key – foreign key relationships. However, in MongoDB, 1:1,
1:N, N:1, or N:N relationships can be modeled by two means, namely, embedded
and referenced approaches. In the first approach, one document is embedded
inside another document, and thus all the related data are located in a single
document. On the other hand, in the referenced approach, documents will be
maintained separately; however, documents have a reference field containing the
address of the other documents.
Table 4.1 Relationship of
RDBMS terminology with
MongoDB
RDBMS
MongoDB
Database
Database
Table
Collection
Row
Document
Column
Field
Primary key Primary key (MongoDB provides
the default key _id itself)
F. Firouzi and B. Farahani
On the other hand, NoSQL is used:
• When ACID support is not required
• When a traditional RDBMS model is insufficient
• When data being stored requires flexible schema
• When constraints or validation logic is not needed
• When logging data from distributed sources
• When storing temporary data or wish lists and session data
4.6.1.1 MongoDB
MongoDB is a document-oriented, cross-platform database that offers high performance and data availability while being easily scalable; MongoDB is able to support
diverse schema, balance loads, handle replication, indexing, queries, and filing (i.e.,
to work as a file system) [16, 18].
• Collection: A group of MongoDB documents is called a collection. Documents in
MongoDB are equivalent to tables in RDBMS. Documents housed in a collection
may contain diverse fields; however, all documents in a particular collection are
used for a similar or related purpose.
• Document: A document is known as a set of key-value pairs, often with dynamic
schema, meaning documents within the same collection are not required to have
identical fields or structures and common document fields may hold different
data. Table 4.1 illustrates the relationship between RDBMS terminology and
MongoDB. Figure 4.15 also shows the MongoDB document structure of a blog
site using a comma-separated key-value pair.
• Relationship: In MongoDB, relationships illustrate how different documents
are logically connected to each other. Unfortunately, MongoDB cannot support
traditional primary key – foreign key relationships. However, in MongoDB, 1:1,
1:N, N:1, or N:N relationships can be modeled by two means, namely, embedded
and referenced approaches. In the first approach, one document is embedded
inside another document, and thus all the related data are located in a single
document. On the other hand, in the referenced approach, documents will be
maintained separately; however, documents have a reference field containing the
address of the other documents.
Table 4.1 Relationship of
RDBMS terminology with
MongoDB
RDBMS
MongoDB
Database
Database
Table
Collection
Row
Document
Column
Field
Primary key Primary key (MongoDB provides
the default key _id itself)
