-
In which year, Bombay city has been officially renamed as Mumbai
-
Which fort is the birthplace of Chhatrapati Shivaji Maharaj
-
Which one is the highest point in Maharashtra
-
Who is known as the Political Guru of Mahatma Gandhi
- A. Ravindra Kelekar
- B. Bal Gangadhar Tilak
- C. Gopal Krishna Gokhale Correct Answer
- D. None of the Above
-
Who was the first Chief Minister of Maharashtra
-
Which day is celebrated as the Maharashtra Day
-
In which year the Bombay High Court was established
-
Approximately how many forts are there in Maharashtra
-
Total number of Districts in Maharashtra
-
Which marathi newspaper was published by Bal Gangadhar Tilak
-
When the third battle of Panipat was fought between Maratha and Afghan army
-
In which year, Elephanta Caves designated as a UNESCO World Heritage Site
-
Which one is the longest river in Maharashtra
-
The Maharashtra State was formed by the Bombay Reorganisation Act in the year
-
Total number of Parliamentary Constituency
-
Who was the first Marathi litterateur to win the Jnanpith Award
-
Who is known as the spiritual guru of Shivaji
-
What is the literacy rate of Maharastra according to 2011 census
-
The Bandra" Worli Sea Link Bridge was opened for public in the year
-
In which year the Mumbai University was established
-
Who was the first person of Maharashtra to received Bharat Ratna Award
-
The Nagpur city is also known as the _________ city of India
-
Which king of England had been presented with the Mumbai city as a dowry from Portugal
-
In which year the construction of Chatrapati Shivaji Terminus was completed
-
The Bhoodan movement was started by ___________ in 1951
-
Which one is recognised as state tree in Maharastra
-
Who was the first Vice Chancellor of Mumbai University
-
In which year, the construction of Gateway of India was completed
-
The Gateway of India was erected to mark the landing of which King
-
Which one is the largest district by area wise in Maharastra
Maharashtra GK Question and Marathi General Knowledge
How to Rename Document field in MongoDB and $rename Operator
Sometime We want to Rename the Document field in Collection MongoDB using $rename Operator. Again by using collection method we can do it easily. whenever we want to rename the document field we have to use $rename operator.
db.collectionName.update( criteria, objNew, upsert, multi )
Criteria : This will hold the criteria for updating the document. Here you can specify the condition whether you want to update all the document or few document in collection.
objNew : $operator which will manipulate the object.
upsert : It is Upsert Operation which will insert the record if it doesn't exist.
multi : Indicates matched documents criteria should be updated or just one Document.
MongoDB Rename Document field
Create studentInfo DB in mongoDB using below command as well as create student collection and insert Document in it.
Now we will have some document sample from student collection. By using below query we will fetch document.
db.student.find().pretty()
Output of Above query is below.
{ "_id" : ObjectId("5ebeaafd50845b5c0ea8bf54"), "id" : 1, "name" : "M Kumar", "dob" : "2003-04-07", "marks" : 54, "created_at" : "2017-11-13 23:33:42", "isOpen" : false, "status" : 1 } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf55"), "id" : 2, "name" : "MOHAMMED ISHAQ H", "dob" : "2002-06-14", "marks" : 67, "created_at" : "2016-11-13 23:33:42", "isOpen" : false, "status" : 1, "exam_status" : "PASSED" }
Rename the Document field "name" as "fullName"
In the above document we will rename the field "name" using below query which uses $rename operator to do that.
db.student.update({},{$rename :{"name":"fullName"}}, false, true)
This above query will rename the document filed. after executing this we will fetch the document again. Output is below.
{ "_id" : ObjectId("5ebeaafd50845b5c0ea8bf54"), "id" : 1, "dob" : "2003-04-07", "marks" : 54, "created_at" : "2017-11-13 23:33:42", "isOpen" : false, "status" : 1, "fullName" : "M Kumar" } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf55"), "id" : 2, "dob" : "2002-06-14", "marks" : 67, "created_at" : "2016-11-13 23:33:42", "isOpen" : false, "status" : 1, "exam_status" : "PASSED", "fullName" : "MOHAMMED ISHAQ H" }
Add a new field to all documents in a collection in MongoDB
Sometime You want to add new fields in existing document in MongoDB collection. You must follow this. Lets Start with example and we will add the new field in the document.
Adding new Field in Existing Document Collection
Create studentInfo Database in MongoDB server. Use the below code for creating the DB. Use db.createCollection("collection-Name") and create student Collection and insert Document in mongoDB.
Insert Some Document in student collection where further we can apply the MongoDB Collection Methods to add new field in existing document in student Collection. Inserted document in student Collection. Below is the document list present in student collection.
db.collection.update( criteria, objNew, upsert, multi )
Criteria : This will hold the criteria for updating the document. Here you can specify the condition whether you want to update all the document or few document in collection.
objNew : $operator which will manipulate the object.
upsert : It is Upsert Operation which will insert the record if it doesn't exist.
multi : Indicates matched documents criteria should be updated or just one Document.
Above command will add the new field in existing document of Student Collection. Run the command and again fetch the document using find() method you will see that all the document got updated with status filed.
All the document have the new field named with status and value is assigned to 1.
this above query will add the exam_status field with value pass if the marks is greater then 60. check the below code and the output.
{ "_id" : ObjectId("5ebeaafd50845b5c0ea8bf54"), "id" : 1, "name" : "M Kumar", "dob" : "2003-04-07", "marks" : 54, "created_at" : "2017-11-13 23:33:42" } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf55"), "id" : 2, "name" : "MOHAMMED ISHAQ H", "dob" : "2002-06-14", "marks" : 67, "created_at" : "2016-11-13 23:33:42" } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf56"), "id" : 3, "name" : "ANBUSELVAM S", "dob" : "2004-06-18", "marks" : 87, "created_at" : "2019-11-13 23:33:42" } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf57"), "id" : 4, "name" : "MARTINPRIYADOSS J", "dob" : "2004-03-08", "marks" : 43, "created_at" : "2012-11-13 23:33:42" } { "_id" : ObjectId("5ebf58376803d36568082c60"), "id" : 5, "name" : "JAGAN J", "dob" : "2003-04-10", "marks" : 98, "created_at" : "2012-11-13 23:33:42" }
Add New fields in existing Document in Collection
Syntax for Update method in MongoDB is below. By using the below customize code we will add new field in document.db.collection.update( criteria, objNew, upsert, multi )
Criteria : This will hold the criteria for updating the document. Here you can specify the condition whether you want to update all the document or few document in collection.
objNew : $operator which will manipulate the object.
upsert : It is Upsert Operation which will insert the record if it doesn't exist.
multi : Indicates matched documents criteria should be updated or just one Document.
Adding new field in the student Collection
Now we will Add new Field named status in student Collection document and set the value to 1. Below is the code for your reference.db.student.update({}, {$set :{"status": 1}}, false, true)
Above command will add the new field in existing document of Student Collection. Run the command and again fetch the document using find() method you will see that all the document got updated with status filed.
db.student.find().pretty()
All the document have the new field named with status and value is assigned to 1.
{ "_id" : ObjectId("5ebeaafd50845b5c0ea8bf54"), "id" : 1, "name" : "M Kumar", "dob" : "2003-04-07", "marks" : 54, "created_at" : "2017-11-13 23:33:42", "isOpen" : false, "status" : 1 } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf55"), "id" : 2, "name" : "MOHAMMED ISHAQ H", "dob" : "2002-06-14", "marks" : 67, "created_at" : "2016-11-13 23:33:42", "isOpen" : false, "status" : 1 } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf56"), "id" : 3, "name" : "ANBUSELVAM S", "dob" : "2004-06-18", "marks" : 87, "created_at" : "2019-11-13 23:33:42", "isOpen" : false, "status" : 1 } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf57"), "id" : 4, "name" : "MARTINPRIYADOSS J", "dob" : "2004-03-08", "marks" : 43, "created_at" : "2012-11-13 23:33:42", "isOpen" : false, "status" : 1 } { "_id" : ObjectId("5ebf58376803d36568082c60"), "id" : 5, "name" : "JAGAN J", "dob" : "2003-04-10", "marks" : 98, "created_at" : "2012-11-13 23:33:42", "isOpen" : false, "status" : 1 }
Add new Filed exam_status as Pass in Document if marks > 60
Query to add new field exam_status as pass if the marks greater then 60. Below is the code which will add new fields in student collection.db.student.update({marks : {$gt :60}}, {$set :{"exam_status" : "PASSED"}}, false, true)
this above query will add the exam_status field with value pass if the marks is greater then 60. check the below code and the output.
db.student.find().limit(3).pretty()
{ "_id" : ObjectId("5ebeaafd50845b5c0ea8bf54"), "id" : 1, "name" : "M Kumar", "dob" : "2003-04-07", "marks" : 54, "created_at" : "2017-11-13 23:33:42", "isOpen" : false, "status" : 1 } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf55"), "id" : 2, "name" : "MOHAMMED ISHAQ H", "dob" : "2002-06-14", "marks" : 67, "created_at" : "2016-11-13 23:33:42", "isOpen" : false, "status" : 1, "exam_status" : "PASSED" } { "_id" : ObjectId("5ebeaafd50845b5c0ea8bf56"), "id" : 3, "name" : "ANBUSELVAM S", "dob" : "2004-06-18", "marks" : 87, "created_at" : "2019-11-13 23:33:42", "isOpen" : false, "status" : 1, "exam_status" : "PASSED" }
Subscribe to:
Posts (Atom)
Our Feature Post
There is a tree between houses of A and B If the tree leans on As House
There is a tree between houses of A and B. If the tree There is a tree between houses of A and B. If the tree leans on A’s House, the t...
Our Popular Post
-
👉 Reema can complete a piece of work in 12 days while Seema can the same work in 18 days. If they both work together, then how many da...
-
Probability Question and Solutions Two dice are thrown simultaneously. What is the probability of getting two numbers whose product...
-
The average of 11 numbers is 30. If the | Solutions The average of 11 numbers is 30 . If the average of first six numbers is...
-
Karan, Hari and Kowshik play cricket. The runs got by Karan to Hari and Hari to Kowshik are in the ratio of 5:3. They get altogether 588 ...
-
Analogies Questions :: Logical Reasoning 👉 Analogies shortcut tricks, Formula, Method and Notes 👉 Analogies Questions and a...