Difference between revisions of "MongoDB Documents"

From mi-linux
Jump to navigationJump to search
Line 31: Line 31:
 
If a collection does not exist, MongoDB creates the collection when you first store data for that collection.
 
If a collection does not exist, MongoDB creates the collection when you first store data for that collection.
  
The following example will create a collection representing the DEPT/EMP schema seen in the [Oracle_Schema|Oracle Workbook].
+
The following example will create a collection representing the DEPT/EMP schema seen in the [[Oracle_Schema|Oracle Workbook]].

Revision as of 18:01, 18 October 2016

Main Page >> MongoDB >>MongoDB Workbook >> MongoDB Documents

Document Database

MongoDB is an example of a NoSQL Document database. This means in MongoDB, databases hold collections of documents. Each student has their own individual database, where documents can be created.

You can think of a record in MongoDB as being a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The documents can be complex, where the values of fields can include other documents, arrays and arrays of documents.

For example, a record for a lecturer could be:

 {
    name: "myName",
    roomNo: "MI412",
    telNo:  "2222"
    qualifications: ["BSc Computer Science", "MSc Advanced Computing", "PhD NoSQL Databases"]
    jobTitle: "Senior Lecturer"
 }

This follows a field:value pair format.

Where: name, roomNo, telNo, qualifications and jobTitle are fields and myName, MI412, 2222, ["BSc Computer Science", "MSc Advanced Computing", "PhD NoSQL Databases"] and Senior Lecturer are values.

Collections

MongoDB stores its documents in a collection. Collections can be compared to tables in a relational database.

Create a Collection

If a collection does not exist, MongoDB creates the collection when you first store data for that collection.

The following example will create a collection representing the DEPT/EMP schema seen in the Oracle Workbook.