Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts

Thursday, June 8, 2017

RDBMS Where Clause Equivalents in MongoDB

RDBMS Where Clause Equivalents in MongoDB:


To query the document on the basis of some condition, you can use following operations.

Operation
Syntax
Example
RDBMS Equivalent
Equality {<key>:<value>} db.mycol.find({"by":"tutorials point"}).pretty() where by = 'tutorials point'
Less Than {<key>:{$lt:<value>}} db.mycol.find({"likes":{$lt:50}}).pretty() where likes < 50
Less Than Equals {<key>:{$lte:<value>}} db.mycol.find({"likes":{$lte:50}}).pretty() where likes <= 50
Greater Than {<key>:{$gt:<value>}} db.mycol.find({"likes":{$gt:50}}).pretty() where likes > 50
Greater Than Equals {<key>:{$gte:<value>}} db.mycol.find({"likes":{$gte:50}}).pretty() where likes >= 50
Not Equals {<key>:{$ne:<value>}} db.mycol.find({"likes":{$ne:50}}).pretty() where likes != 50

ResourceLink: https://www.tutorialspoint.com/mongodb/mongodb_query_document.htm

Advantages of MongoDB over RDBMS

The Advantages of MongoDB over RDBMS are


1. No schema migrations. Since MongoDB is schema-free, your code defines your schema.

2. Number of fields, content and size of the document can be different from one document to another.

3. Tuning using indexes

4. Ease of scale-out: MongoDB is easy to scale by adding commodity hardware

5. Conversion / mapping of application objects to database objects not needed since MongoDB uses object notation to represent data structures

6. Schemaless: MongoDB is document database in which one collection holds different documents.

7. Uses internal memory for storing the working set, enabling faster access of data

8. A document-based data model. The basic unit of storage is analogous to JSON, Python dictionaries, Ruby hashes, etc. This is a rich data structure capable of holding arrays and other documents.

9. A clear path to horizontal scalability.

10. Structure of a single object is clear and well defined

11. No complex joins required to bring together related data

12. Deep query-ability. MongoDB supports dynamic queries on documents using a document-based query language that's nearly as powerful as SQL




Relationship of RDBMS terminology with MongoDB

The following table shows the relationship of RDBMS terminology with MongoDB.
RDBMS
MongoDB
Database Database
Table Collection
Tuple/Row Document
column Field
Table Join Embedded Documents
Primary Key Primary Key (Default key _id provided by mongodb itself)
Database Server and Client
Mysqld/Oracle mongod
mysql/sqlplus mongo




  • Collection(Table) is a group of MongoDB documents(rows).
  • Documents(rows) within a collection(table) can have different fields(columns).
  • Document is a set of key-value pairs.