Blog
0

MongoDB: An Introduction

  • Pradyumn Sharma
  • June 6, 2017

Tags: ,

In my blog post titled “An Introduction to NoSQL“, I had talked about some of the key characteristics of NoSQL databases. In this article, we’ll look at some key concepts and features of MongoDB, one of the most prominent NoSQL database solutions.

MongoDB is a leading document oriented NoSQL database solution that is good at storing very large volumes of data. In fact, its name is derived from the word “huMONGOus”. You can configure a MongoDB cluster with hundreds or thousands of servers, providing linear scalability.

Documents and Collections

When you want to store some data in MongoDB, you provide it as a JSON document. Here are examples of such documents:

1
2
3
4
{ _id:1, name: 'Ahmad', gender: 'M', dept: 'Fin'}
{ _id:2, name: 'Bajrang', gender: 'M', dept: 'Sales'}
{ _id:3, name: 'Catherine', gender: 'F', dept: 'HR'}
{ _id:4, name: 'Dostoyevski', gender: 'M', dept: 'Prod'}

A document in MongoDB is conceptually similar to a record in a typical relational database like MySQL or Oracle. Documents in MongoDB are stored in a collection (equivalent to a table in a relational database).

Documents can have sub-documents, as well as collections of values or sub-documents. For example, the following is a valid document to store in a MongoDB collection (and a pretty natural thing to do so):

1
2
3
4
5
6
7
8
9
10
11
12
{
    name: {first: 'Harish', last: 'Chandra'},
    gender: 'M',
    yearOfBirth: 1962,
    livesIn: 'Mumbai',
    countriesVisited: ['India', 'Singapore', 'Thailand', 'United Kingdom', 'Spain', 'Denmark',
                       'United States of America'],
    languages: [
        {name: 'Hindi', proficiency: 'Fluent'},
        {name: 'English', proficiency: 'Fluent'},
        {name: 'Sanskrit', proficiency: 'Intermediate'} ]
}

You don’t define a structure for a MongoDB collection. This means that different documents in a collection may have different fields and MongoDB will ingest them all as a part of the same collection! For example, you can insert the following two documents in the same collection:

1
2
3
4
5
6
7
8
9
10
11
12
{
    name: 'Narayan Subramanian',
    gender: 'M',
    currentCity: 'Jaipur'
}
 
{
    name: 'Pushpa Maheshwari',
    gender: 'F',
    email: 'pushpa@example.com',
    worksAt: 'Indian Railways'
}

Rich Query Language

MongoDB provides a rich query language for database operations. It’s query language is built around the JSON format and is different from traditional SQL in terms of syntax. Here are some examples of the CRUD (Create, Read, Update, Delete) operations:

Inserting a document in a collection:

1
2
3
4
5
6
db.books.insert (
    {
        title: 'To Kill a Mockingbird',
        author: 'Harper Lee'
    }
)

In “persons” collection, find all males born before 1970 and all females born before 1980, sort by first name and last name of such persons:

1
2
3
4
5
6
db.persons.find (
    {$or: [
        {gender: 'M', yearOfBirth: {$lt: 1970} },
        {gender: 'F', yearOfBirth: {$lt: 1980} }
    ] }
).sort ( {'name.first': 1, 'name.last': 1} )

MongoDB’s search operations are quite powerful. You can perform searches inside sub-documents as well as collections within documents.

In “persons” collection, update the document for ‘Merilyn Holmes’, setting gender to ‘F’, ‘yearOfBirth’ to ‘1997’, and ‘married’ to ‘N’:

1
2
3
4
db.persons.update (
    {name: {first: 'Merilyn', last: 'Holmes'} },
    {$set: {gender: 'F', yearOfBirth: 1997, married: 'N'} }
)

You can also update individual elements within collections embedded within documents.

Delete all males from the “persons” collection:

1
db.persons.remove ( {gender: 'M'} )

Some Other Features of MongoDB

  • Indexes are supported for fast retrieval of documents, just like relational databases.
  • Text indexing is supported to perform full text queries on documents.
  • You can have geospatial information in a collection, and perform powerful search operations (such as “find all restaurants within 1000 meters radius from a given position”)
  • Read-only views are a recent addition to MongoDB.
  • You can write Javascript code, both for client-side and server-side operations.
  • An aggregation framework provides more flexible and powerful query operations on collections. The framework works like a pipeline of various operations such as filter, transform, sort, grouping operation, left outer join with another collection, etc.
  • Drivers are available for all the mainstream programming languages.
  • For high availability, you can configure automatic replication with up to 49 servers automatically backing up the data from a primary server.
  • For high performance, you can partition your data across multiple “shards” (each shard being a single server or a replica set), so that workload is distributed across multiple partitions.

Closing Thoughts

All in all, MongoDB reduces some of the restrictions that traditional relational databases impose enabling us to design a database and write queries that better serve the demands of today’s applications (such as mobile services, querying large volume of data, data pipelines, etc).

MongoDB is not a replacement to relational databases. Instead it is a welcome addition to the field of database technology, providing solutions to problems that were hard or inefficient to solve using the traditional approach. That it provides great horizontal scalability and performance is an added benefit.


27 responses to “MongoDB: An Introduction”

  1. I am so grateful for your blog article.Much thanks again. Cool.

  2. Muchos Gracias for your article.Really looking forward to read more. Want more.

  3. wow, awesome blog post.Really thank you! Great.

  4. Wow, great post.Really thank you! Really Cool.

  5. Im thankful for the article post.Much thanks again. Will read on…

  6. I’ve got entertaining by using, produce I came across what exactly I was writing about intended for.. aplikasi berita saham terkini You might have broken this three morning extended quest! The almighty Bless you man. Employ a great morning. Bye

  7. “Hey! Would you mind if I share your blog with my zynga group? There’s a lot of people that I think would really appreciate your content. Please let me know. Many thanks”

  8. This blog is definitely rather handy since I’m at the moment creating an internet floral website – although I am only starting out therefore it’s really fairly small, nothing like this site. Can link to a few of the posts here as they are quite. Thanks much. Zoey Olsen

  9. Aerie Promo says:

    Hi there! This post couldn’t be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!

  10. Very interesting subject, regards for posting. “If you have both feet planted on level ground, then the university has failed you.” by Robert F. Goheen.

  11. Very portion of written content.. beli palletized I just discovered your internet site and in accession funds to mention that we purchase essentially liked account your blog content. However I’ll be opt-in on your feeds or perhaps We good results you can get having access to continually easily.

  12. Amazing problems here. Now i am quite content to peer your post. Many thanks a whole lot using this program .. trader saham indonesia having a look toward call you. Are you going to generously decline us a snail mail?

  13. That you are a outstanding web marketer. Your website loading swiftness will be incredible horizontal mixer indonesia. It seems that you do any kind of exclusive secret. On top of that, Your subject matter are generally mona lisa. you could have performed a excellent approach within this subject!

  14. Hi all product endorsement. Today making use of bing. It really is a truly efficiently prepared write-up. I am going to make sure you book mark the idea and come time for find out more of one’s helpful details. Wanted post. I will surely give back.

  15. debellis says:

    Woah this particular blog site is wonderful everyone loves learning the articles you write cara main saham online. Keep within the wonderful operate! You’re sure, everybody is hunting game just for this info, it is possible to guide these individuals considerably.

  16. I’ve truly find out a number of exceptional things here aplikasi berita saham terbaru. Certainly value bookmarking intended for revisiting. I shock how the whole lot endeavor you put to create these superb educational website.

  17. DKNY 【富士蘋果系列】富士蘋果鬍後乳的商品介紹 DKNY,富士蘋果系列,富士蘋果鬍後乳

  18. Heya now i am somebody in charge of here. I ran across this particular aboard and that i to get It truly valuable & them helped me to out and about lots. I’m hoping to give something again and support some others like you served everyone.. aplikasi android berita saham terbaru

  19. Your post on MongoDB: An Introduction – Pragati Software is very good. I hope you can continue delivering many more article in the future. Long live 24x7weboffers.in

  20. Amazing issues entirely, you only need to earned a brand new viewer. Precisely what do you propose when it comes to your post that you produced few days in the past? Any a number of?

  21. 9合1升級保護,提升全面防護!!! 相比之前四合一的疫苗只能預防四種hpv病毒,70的相關癌症。 九合一可以預防9種hpv病毒,可預防高達90以上的子宮頸癌、外陰癌、陰道癌和肛門癌及癌前病變等。 HPV9合1子宮頸癌疫苗 Gardasil 功效 100 預防高危致癌的 HPV 16、18、31、33、45、52 及 58 型號 (可減低 90 患子宮頸癌、、90-95 肛門癌、85-90 外陰癌、80-85 陰道癌及相關癌前病變的風險) 100 減低引致生殖器官濕疣 (俗稱「椰菜花」) 的 HPV 6、11 型的感染 (可減低超過 90 患生殖器官濕疣的風險) 男性方面,能減低患上肛門癌、生殖器官濕疣 (俗稱「椰菜花」) 及傳播 HPV 病毒的風險 注射位置紅腫及痛、輕微發燒和頭痛,至今未有嚴重副作用記錄

  22. Ellanse洢蓮絲(依戀詩)是一款荷蘭與英國共同研發的的新型真皮填充劑,是由30的25-50微米(µm)的聚己內酯(polycaprolactone, PCL)完美微型正圓晶球,以及70的PBS-生物降解材料(carboxymethylcellulose, CMC)製成的凝膠體,這些成分都是通過FDA(美國食品藥品監督管理局)和歐洲CE認證的安全成分,在人體內水分和二氧化碳作用下可以完全被分解吸收和排出的安全物質,對人體不會產生過敏反應,因此治療前不需經過敏檢測,在使用上幾乎不產生副作用。

  23. 痘疤治療 says:

    加強優化面部輪廓,可被身體完全吸引,能自然地修飾面部輪廓 功效可長達24個月以上 JUVEDERM的特點: 效果立即可見 非永久性 非手術性 安全有效 效果自然 JUVEDERM獲歐盟(CE)及美國及藥物管理局(FDA)認證 首先及唯一獲得FDA認證在首次療程後能維持長達一年2-4功效 新世代專員Hylacross科技為產品帶來獨特的物理特質,包括凝聚力、支撐力及柔順度 8點提升 這是一套由全球著名醫學美容醫生Dr. Maurício de Maio,以JUVÉDERM®系列透明質酸產品為基礎而研發的面部優化療程,藉著簡單程序便達致面部優化效果,不需進行手術,減低風險。 此療程會根據病人的個別情況,重點針對面部8個最常因流失膠原蛋白及彈性纖維而凹陷的位置,再依據特定的順序,從顴骨至下巴位置配合JUVÉDERM®系列的透明質酸產品進行療程,從而改善這些位置的豐盈度及滑溜度,全面性優化面部輪廓。

  24. Google Adwords 關鍵字廣告

  25. FineScan 會在肌膚上製造數以千計的細小深入傷口,即所謂的顯微加熱區(microthermal zone),但要確保每次治療時皆有部份組織不受能量影響,於是,每一個顯微加熱區的作用雖然強烈而明顯,但周圍都包覆著正常且結構完整的皮膚組織,使傷口能在短時間內癒合,並替換之前有缺陷的受損組織。Finescan不僅可讓表皮新生,更可促進深層膠原再生,從內而外徹底喚醒細胞,瞬時找回年輕時的肌膚狀態。憑藉最新的雙軸技術,FINESCAN 6可治療 – 面部 – 頸部 – 暗瘡凹凸洞 – 增生性疤痕

  26. 韓國膠原蛋白提拉線,在韓國又稱作FTL(Fine Thread Lifting細線埋入拉提術)」,可達到最新趨勢V臉回春效果。它是運用獲得韓國食品藥品管理局KFDA最高安全等級認證的可吸收縫線PDO (polydioxanone)的Fine Thread(細螺紋) 埋入皮膚真皮層裡作用,利用異物反應原理,促進皮膚真皮膠原的增生、刺激局部微循環、從而提拉皮膚和肌肉,增強皮膚彈性,達到提升、除皺,美白、嫩膚等多重回春效果。

Leave a Reply

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

© 2017 Pragati Software Pvt. Ltd. All Rights Reserved.

Enquiry