mongodb documents

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

Apart from java, we are going to start this tutorial series which will explain about mongoDB which is a trend in noSQL databases. We know mongoDB is a key value pair based database and just like rows in relational database, mongodb documents store the data. Instead of rows, mongoDB is documents.

MongoDB Documents:

MongoDB is not relational database and hence the data that is to be inserted in it need not have a fixed structure. Consider the case of relational database where each rows will have fixed number of columns/fields, the values can be null but the row can accommodate only those fields. There is no flexibility in it. MongoDB documents solve this problem. They can have any number of fields which are composed of key value pairs. H

The format of mongodb documents is as below

 

Now there are certain rules associated with naming convention of fields in mongoDB documents which are as below

  • Fields names cannot be null
  • Field names cannot start with $ sign
  • Field name cannot contain dot (.) character. This is because dot (.) character is used to navigate to embedded mongoDB documents which we will see in further tutorials
  • Every document is identified by a default field called “_id” which is of type

An example for mongoDB document will be as below

Most of the times when we are dealing with queries, we are going to use mongodb documents, the structure for query selector as well as update queries in specified in the format of document itself.

MongoDB  _Id:

  • Just like primary keys in relational databases, mongoDB has a field called _id.
  • It is always the first field for every document
  • If you do not specify _id, then mongoDB will create one and put as first field of document.
  • MongoDB applies unique constraint to _id so that each document can be identified with it.

I hope this article gives a vague idea about mongodb documents.

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

One thought on “mongodb documents

Leave a Reply

Your email address will not be published. Required fields are marked *