Hide ID Field in MongoDB

AmitDiwan
Updated on 15-May-2020 05:50:19

634 Views

Let us create a collection with documents −> db.demo575.insertOne({id:101, Information:{Name:"Chris", Age:21}});{    "acknowledged" : true, "insertedId" : ObjectId("5e916a55581e9acd78b427f7") } > db.demo575.insertOne({id:102, Information:{Name:"David", Age:20}});{    "acknowledged" : true, "insertedId" : ObjectId("5e916a5f581e9acd78b427f8") } > db.demo575.insertOne({id:101, Information:{Name:"Bob", Age:23}});{    "acknowledged" : true, "insertedId" : ObjectId("5e916a67581e9acd78b427f9") }Display all documents from a collection with the help of find() method −> db.demo575.find();This will produce the following output −{ "_id" : ObjectId("5e916a55581e9acd78b427f7"), "id" : 101, "Information" : { "Name" : "Chris", "Age" : 21 } } { "_id" : ObjectId("5e916a5f581e9acd78b427f8"), "id" : 102, "Information" : { "Name" : "David", "Age" : 20 } } { "_id" ... Read More

Working with Aggregation to Match All Values in MongoDB

AmitDiwan
Updated on 15-May-2020 05:48:36

534 Views

To match all the values in MongoDB, use $match along with $and in Aggregation. Let us create a collection with documents −> db.demo574.insertOne( ...    { ...       "details1": { ...          "details2": { ...             "dueDate": new ISODate("2020-01-10"), ...             "Name": "Chris", ... ...             "UserInformation": { ...                "Name": "John", ...                "Marks": 78 ...             }, ...       ... Read More

Query an Array of Embedded Documents in MongoDB

AmitDiwan
Updated on 15-May-2020 05:45:05

194 Views

For this, use $push along with update. Let us create a collection with documents −> db.demo573.insertOne( ...    { ...       '_id' :101, ...       'SearchInformation' : [ ...          { ...             'Site' : 'Facebook.com', ...             'NumberOfHits' : 100 ...          }, ...          { ...             'Site' : 'Twitter.com', ...             'NumberOfHits' : 300 ...          } ...       ... Read More

MongoDB Query with Case Insensitive Search

AmitDiwan
Updated on 15-May-2020 05:41:07

2K+ Views

For case, insensitive search, use regex in find() method. Following is the syntax −db.demo572.find({"yourFieldName" : { '$regex':/^yourValue$/i}});To understand the above syntax, let us create a collection with documents −> db.demo572.insertOne({"CountryName":"US"});{    "acknowledged" : true, "insertedId" : ObjectId("5e915f0e581e9acd78b427f1") } > db.demo572.insertOne({"CountryName":"UK"});{    "acknowledged" : true, "insertedId" : ObjectId("5e915f17581e9acd78b427f2") } > db.demo572.insertOne({"CountryName":"Us"});{    "acknowledged" : true, "insertedId" : ObjectId("5e915f1b581e9acd78b427f3") } > db.demo572.insertOne({"CountryName":"AUS"});{    "acknowledged" : true, "insertedId" : ObjectId("5e915f20581e9acd78b427f4") } > db.demo572.insertOne({"CountryName":"us"});{    "acknowledged" : true, "insertedId" : ObjectId("5e915f25581e9acd78b427f5") }Display all documents from a collection with the help of find() method −> db.demo572.find();This will produce the following output −{ "_id" : ObjectId("5e915f0e581e9acd78b427f1"), ... Read More

Find Value Above a Specific Value in MongoDB Documents

AmitDiwan
Updated on 15-May-2020 05:39:06

221 Views

To find values above a specific value, the following is the syntax using $gte in MongoDB −db.yourCollectionName.find({yourFieldName:{$gte:yourValue}});Let us create a collection with documents −> db.demo571.insertOne({"Price":140});{    "acknowledged" : true, "insertedId" : ObjectId("5e909b3439cfeaaf0b97b587") } > db.demo571.insertOne({"Price":100});{    "acknowledged" : true, "insertedId" : ObjectId("5e909b3639cfeaaf0b97b588") } > db.demo571.insertOne({"Price":110});{    "acknowledged" : true, "insertedId" : ObjectId("5e909b3839cfeaaf0b97b589") } > db.demo571.insertOne({"Price":240});{    "acknowledged" : true, "insertedId" : ObjectId("5e909b3c39cfeaaf0b97b58a") }Display all documents from a collection with the help of find() method −> db.demo571.find();This will produce the following output −{ "_id" : ObjectId("5e909b3439cfeaaf0b97b587"), "Price" : 140 } { "_id" : ObjectId("5e909b3639cfeaaf0b97b588"), "Price" : 100 } { "_id" : ... Read More

Use Placeholder Attribute in HTML

Anvi Jain
Updated on 14-May-2020 10:54:04

5K+ Views

If you want to set a hint for text area or input field, then use the HTML placeholder attribute. The hint is the expected value, which gets displayed before the user enters a value, for example, name, details, etc.ExampleYou can try to run the following code to learn how to use placeholder attribute in HTML.           Register                                              

Use Geolocation Coordinates in HTML5

Nishtha Thakur
Updated on 14-May-2020 10:46:51

401 Views

HTML5 Geolocation API lets you share your location with your favorite websites. A Javascript can capture your latitude and longitude and can be sent to backend web server and do fancy location-aware things like finding local businesses or showing your location on a map. The geolocation coordinates specifies the geographic location of the device.Geolocation methods getCurrentPosition() and getPositionUsingMethodName() specify the callback method that retrieves the location information. These methods are called asynchronously to an object Position which stores the complete location information.The Position object specifies the current geographic location of the device. The location is expressed as a set of ... Read More

Use the formmethod Attribute in HTML

Nancy Den
Updated on 14-May-2020 10:22:35

190 Views

The formmethod attribute is used to define the HTTP technique for sending form information. This method is usedwith input type submit a picture. It overrides the method attribute of HTML forms.ExampleYou can try to run the following code to learn how to use the formmethod attribute in HTML.           HTML formmethod attribute                        Student Name          Student Subject                              

MongoDB Query for Counting Distinct Values Across All Documents

AmitDiwan
Updated on 14-May-2020 10:22:06

456 Views

For this, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo718.insertOne( ...    { ...       "id":101, ...       "details": ...       { ...          "OtherDetails": ["Chris", "Mike", "Sam"], "GroupName": ["Group-1"], "Info": [] ...       } ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5eaae25843417811278f5880") } > db.demo718.insertOne( ...    { ...       "id":102, ...       "details": ...       { ...          "OtherDetails": ["Chris", "David"], "GroupName": ["Group-1"], "Info": [] ...   ... Read More

Aggregate and Group by Date in Nested Documents

AmitDiwan
Updated on 14-May-2020 10:20:20

277 Views

For aggregation, use aggregate() in MongoDB. Group the dates with $group. Let us create a collection with documents −> db.demo717.insertOne( ...    { ...       "shippingdetails": ...       [ ...          { ...             duedate:"2020-04-29 22:33:04", ...          }, ...          { ...             duedate:"2020-03-29 22:33:04", ...          }, ...          { ...             duedate:"2020-04-29 22:33:04", ...          }, ...       ... Read More

Advertisements