Found 1659 Articles for Big Data Analytics

Search by property name for any document with that property in MongoDB?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

181 Views

You can use $ne operator for this. Let us first create a collection with documents −> db.searchByPropertyName.insertOne({"FirstName":"Larry", "Age":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbaf7af7219729fde21ddb5") } > db.searchByPropertyName.insertOne({"FirstName":null, "Age":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbaf7b97219729fde21ddb6") } > db.searchByPropertyName.insertOne({"FirstName":"John", "Age":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbaf7c57219729fde21ddb7") } > db.searchByPropertyName.insertOne({"FirstName":null, "Age":25}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbaf7d07219729fde21ddb8") } > db.searchByPropertyName.insertOne({"FirstName":"David", "Age":20}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbaf7df7219729fde21ddb9") }Following is the query to display all documents from the collection with the help of find() prettyprint −> db.searchByPropertyName.find().pretty();This will produce ... Read More

MongoDB query to find the highest numeric value of a column?

Samual Sam
Updated on 02-Jul-2020 11:33:59

132 Views

You can use $not operator along with $type for this. Let us first create a collection with documents −> db.highestNumericValueOfAColumnDemo.insertOne( ...    { ...       "StudentName": "John", ...       "StudentMathMarks":69 ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cba05727219729fde21ddb1") } > db.highestNumericValueOfAColumnDemo.insertOne( ...    { ...       "StudentName": "Carol", ...       "StudentMathMarks":"89" ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cba059d7219729fde21ddb2") } > db.highestNumericValueOfAColumnDemo.insertOne( ...    { ...       "StudentName": "Chris", ...       "StudentMathMarks":82 ...    } ... ... Read More

Delete a field and value in MongoDB?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

386 Views

To delete a MongoDB field and value, you can use $unset operator. Let us first create a collection with documents −> db.deleteFieldDemo.insertOne({"FirstName":"John", "LastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9fb767219729fde21ddad") } > db.deleteFieldDemo.insertOne({"FirstName":"David", "LastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9fb837219729fde21ddae") } > db.deleteFieldDemo.insertOne({"FirstName":"Carol", "LastName":"Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9fb8d7219729fde21ddaf") }Following is the query to display all documents from the collection with the help of find() method −> db.deleteFieldDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cb9fb767219729fde21ddad"),    "FirstName" : "John",    "LastName" : "Smith" } {    "_id" : ... Read More

How to read a specific key-value pair from a MongoDB collection?

Samual Sam
Updated on 30-Jul-2019 22:30:25

765 Views

You can use dot(.) notation to read a specific key-value pair from MongoDB collection. Let us first create a collection with documents −> db.readSpecificKeyValueDemo.insertOne( ...    { ...       "_id": 100, ...       "StudentDetails": ...       { ...          "StudentFirstName" : "David", ...          "StudentLastName" :"Miller", ...          "StudentAge":23, ...          "StudentCountryName":"US" ...       } ...    } ... ); { "acknowledged" : true, "insertedId" : 100 }Following is the query to display all documents from the collection with the ... Read More

How to remove duplicate values inside a list in MongoDB?

Samual Sam
Updated on 30-Jul-2019 22:30:25

896 Views

You can use aggregate framework along with $setUnion operator. Let us first create a collection with documents −> db.removeDuplicatesDemo.insertOne({"InstructorName":"Chris", "InstructorAge":34, "InstructorSubject":    ["Java", "C", "Java", "C++", "MongoDB", "MySQL", "MongoDB"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9d96c895c4fd159f80807") }Following is the query to display all documents from the collection with the help of find() method −> db.removeDuplicatesDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cb9d96c895c4fd159f80807"),    "InstructorName" : "Chris",    "InstructorAge" : 34,    "InstructorSubject" : [       "Java",       "C",       "Java",       "C++",       "MongoDB",   ... Read More

Fetch records in MongoDB on querying its subset

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

101 Views

You can use $all operator. Let us first create a collection with documents −> db.subsetOfAnArrayDemo.insertOne({"StudentProgrammingSkills":    ["Java", "MongoDB", "MySQL", "C++", "Data Structure", "Algorithm", "Python", "Oracle", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9d1e1895c4fd159f80804") }Following is the query to display all documents from the collection with the help of find() method −> db.subsetOfAnArrayDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cb9d1e1895c4fd159f80804"),    "StudentProgrammingSkills" : [       "Java",       "MongoDB",       "MySQL",       "C++",       "Data Structure",       "Algorithm",       "Python",     ... Read More

Extract subarray value in MongoDB?

Samual Sam
Updated on 30-Jul-2019 22:30:25

359 Views

To extract the subarray value in MongoDB, you can use $elemMatch projection operator.Let us first create a collection with documents −> db.extractSubArrayDemo.insertOne( ...    { ...       _id: 101, ...       "clientName":"Larry", ...       "ClientDetails": ...       [ ...          { ...             "ClientProjectName":"Online Game", ...             "DeveloperTeamSize": 10 ...          }, ...          { ...             "ClientProjectName":"Pig Dice Game", ...             "DeveloperTeamSize": ... Read More

MongoDB query to get specific month|year (not date)?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

594 Views

You can use aggregate framework along with $month projection operator. Let us first create a collection with documents −> db.specificMonthDemo.insertOne({"StudentName":"Larry", "StudentDateOfBirth":new ISODate('1995-01-12')}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9a9ca8f1d1b97daf71819") } > db.specificMonthDemo.insertOne({"StudentName":"Chris", "StudentDateOfBirth":new ISODate('1999-12-31')}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9a9db8f1d1b97daf7181a") } > db.specificMonthDemo.insertOne({"StudentName":"David", "StudentDateOfBirth":new ISODate('2000-06-01')}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9a9ee8f1d1b97daf7181b") }Following is the query to display all documents from the collection with the help of find() method −> db.specificMonthDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cb9a9ca8f1d1b97daf71819"),    "StudentName" : "Larry",    "StudentDateOfBirth" : ISODate("1995-01-12T00:00:00Z") } {    "_id" ... Read More

How do I add a value to the top of an array in MongoDB?

Samual Sam
Updated on 30-Jul-2019 22:30:25

153 Views

To add a value to the top of an array in MongoDB, you can use unshift() −yourArrayName.unshift("yourValue");The above syntax will add the value to the top of an array in MongoDB. Let us first create an array of strings −> technicalSkills=["Java", "MySQL", "C", "SQL SERVER", "ORACLE", "PL/SQL"];This will produce the following output −[ "Java", "MySQL", "C", "SQL SERVER", "ORACLE", "PL/SQL" ]Following is the query to add to the top of an array in MongoDB. Here, we will add “MongoDB” to top of an array using unshift() −> technicalSkills.unshift("MongoDB"); This will produce the following output −7Let us check the “MongoDB” has ... Read More

Finding matching records with LIKE in MongoDB?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

90 Views

Let us first create a collection with documents −> db.likeDemo.insertOne({"Name":"John", Age:32}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb84984623186894665ae41") } > db.likeDemo.insertOne({"Name":"Chris", Age:25}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb84991623186894665ae42") } > db.likeDemo.insertOne({"Name":"Carol", Age:22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb849a1623186894665ae43") } > db.likeDemo.insertOne({"Name":"Johnny", Age:22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb849b2623186894665ae44") } > db.likeDemo.insertOne({"Name":"James", Age:27}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb849bb623186894665ae45") }Following is the query to display all documents from the collection with the help of find() method −> db.likeDemo.find().pretty();This will produce the following output −{    "_id" : ... Read More

Advertisements