Skip to main content

The "case" does matter in MongoDb too!

Sometimes, when working on a particular Technology, we pay a very close attention to some of the features or ways to work on in that technology. However, we tend to ignore other ways. We take a few things for granted, till the day we come across something to the contrary.

This is what happened while working with collections and documents in MongoDb.

I have this Electronics collection :


> db.Electronics.find()
{ "_id" : ObjectId("55685b94fd45377c7f18bccc"), "category" : "TV", "Sales_Date" : "17-11-2014", "amount" : "32000", "currency" : "INR", "Brand" : "Son
y" }
{ "_id" : "00005", "category" : "Laptop", "Sales_Date" : "05-10-2014", "amount" : "28000", "currency" : "INR", "Brand" : "Acer" }

Now I wanted to add a TV of Samsung brand which costs Rs. 27500 and with sales date as 10 June 2016.

I tried to add it as follows:
> db.electronics.insert ( {_id :0006 , category :"TV", brand :"Samsung OLED", sales_date : "10-06-2016", amount :"27500", currency :"INR" })

Now I queried on the collection Electronics again:

> db.Electronics.find()
{ "_id" : ObjectId("55685b94fd45377c7f18bccc"), "category" : "TV", "Sales_Date" : "17-11-2014", "amount" : "32000", "currency" : "INR", "Brand" : "Son
y" }
{ "_id" : "00005", "category" : "Laptop", "Sales_Date" : "05-10-2014", "amount" : "28000", "currency" : "INR", "Brand" : "Acer" }


Hey, where is the Samsung OLED TV?

Any idea, what happened?

Well, for Mongodb, the collection "electronics" is different from "Electronics".
So, when I added the document by using db.electronics.insert...
MongoDb created a new collection called electronics as can be seen from these two statements:

> show collections
Appliances
Electronics
collection
electronics
system.indexes

The above shows two different collections - Electronics and electronics
Also,
db.electronics.find()
shows:
> db.electronics.find()
{ "_id" : 6, "category" : "TV", "brand" : "Samsung OLED", "sales_date" : "10-06-2016", "amount" : "27500", "currency" : "INR" }
>
>
--

The right way to add would be :

db.Electronics.insert ( {_id :0007 , category :"TV", brand :"Samsung OLED", sales_date : "10-06-2016", amount :"27500", currency :"INR" })

I also add two more entries:

db.Electronics.insert ( {_id :0008 , category :"TV", brand :"Panasonic LED", sales_date : "14-06-2016", amount :"31500", currency :"INR" })
db.Electronics.insert ( {_id :0009 , category :"TV", brand :" OLED", sales_date : "12-06-2016", amount :"15500", currency :"INR" })

And final result is now as expected:


> db.Electronics.find()
{ "_id" : ObjectId("55685b94fd45377c7f18bccc"), "category" : "TV", "Sales_Date" : "17-11-2014", "amount" : "32000", "currency" : "INR", "Brand" : "Son
y" }
{ "_id" : "00005", "category" : "Laptop", "Sales_Date" : "05-10-2014", "amount" : "28000", "currency" : "INR", "Brand" : "Acer" }
{ "_id" : 7, "category" : "TV", "brand" : "Samsung OLED", "sales_date" : "10-06-2016", "amount" : "27500", "currency" : "INR" }
{ "_id" : 8, "category" : "TV", "brand" : "Panasonic LED", "sales_date" : "14-06-2016", "amount" : "31500", "currency" : "INR" }
{ "_id" : 9, "category" : "TV", "brand" : " OLED", "sales_date" : "12-06-2016", "amount" : "15500", "currency" : "INR" }
>

Comments

Popular posts from this blog

India's exciting one wicket win over Australia in Mohali test

In an exciting finish in the first test match at Mohali, India beat Australia by 1 wicket. India had to make 216 to win, and at 1 stage India were 124 for 8. Then V.V.S.Laxman and Ishant Sharma had a superb partnership of 81 runs and took India to victory. Laxman remained unbeated on 73, and Ishant made 31. The place where I am currently staying does not subscribes to the sports channel showing this match, but I would surely love to watchthe highlights of this match.

What is this street's name ?

This is another of my Chennai experiences. I had this experience on the street where I stayed at a guest house location till 30th September morning. The street on which I lived is called as "Neelkanda Mehta" street. However, on many homes as well as some other places, it is written as "Neelkanda Metha" street. I have asked other people too. However, I have not found a satisfactory answer.

Evolution and Creationism - My Viewpoint

Whenever someone mentions something related to Evolution ; or whether God created all Animals , Humans ;or whether it is all a play of evolutionary Process; I become very much engrossed. It is a topic in which I have a unique interest . At a personal level,I favour the Theory of Evolution . True , the theory that God created everything does has its valid points . It also has many people supporting it . Points that make the God's creation Theory (as such this is not the name of the Theory , but I call it like this ) : 1)Evolutionists say that Man evolved from Apes who in turm evolved from some Amphibian creatures ,who in tuirn were evolving from Reptiles or Fish and so on . yet ; who created the most basic Life Form ? It must have been God . 2)Who decided when Big Bang has to happen or why Earth only had to be habitable long enough ? True , Mars also has some signs of Life Supporting conditions , but no Life has been detected as such . 3)Why Man only...