Daniol Thomas has Published 197 Articles

How to update the _id of a MongoDB Document?

Daniol Thomas

Daniol Thomas

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

11K+ Views

You cannot update it but you can save a new id and remove the old id. Follow some steps in order to update the _id of a MongoDB. The steps are as follows:Step1: In the first step, you need to store ObjectId into a variable.anyVariableName=db.yourCollectionName.findOne({_id:yourObjectIdValue)});Step 2: In the second step, ... Read More

Best way to store date/time in MongoDB?

Daniol Thomas

Daniol Thomas

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

1K+ Views

There are two different ways by which you can store date/time in MongoDB. In the first approach, you can use Date objects like JavaScript. The Date object is the best way to store date/time in MongoDB. The syntax is as follows:new Date();In the second approach, you can use ISODate(). The ... Read More

How to remove a field completely from a MongoDB document?

Daniol Thomas

Daniol Thomas

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

984 Views

You can use $unset operator to remove a field completely from a MongoDb document. The syntax is as follows:db.yourCollectionName.update({}, {$unset: {yourFieldName:1}}, false, true);To understand the above syntax, let us create a collection with some documents. The query to create a collection with documents are as follows:> db.removeFieldCompletlyDemo.insertOne({"StudentName":"Larry", "StudentFavouriteSubject": ["Java", "C", ... Read More

Add new field to every document in a MongoDB collection?

Daniol Thomas

Daniol Thomas

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

2K+ Views

To add new field to every document in a MongoDB collection, you can use $set operator. The syntax is as follows:db.yourCollectionName.update({}, { $set: {"yourFieldName": yourValue} }, false, true);To understand the above syntax, let us create a collection with some documents. The query to create a collection with documents is as ... Read More

Period hashCode() method in Java

Daniol Thomas

Daniol Thomas

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

141 Views

The hash code value of the Period can be obtained using the hashCode() method in the Period class in Java. This method requires no parameters and it returns the hash code value of the Period.A program that demonstrates this is given as follows:Example Live Demoimport java.time.Period; public class Demo {   ... Read More

How to sort inner array in MongoDB?

Daniol Thomas

Daniol Thomas

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

3K+ Views

You can achieve this with the help of aggregate framework in MongoDB. To understand it, let us create a collection with document. The query to create a collection with document is as follows:> db.sortInnerArrayDemo.insertOne( ... ...    { ...       "EmployeeDetails": ...       { ...   ... Read More

Period getDays() method in Java

Daniol Thomas

Daniol Thomas

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

383 Views

The number of days for a particular Period can be obtained using the getDays() method in the Period class in Java. This method requires no parameters and it returns the number of days in the Period.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo { ... Read More

Period getMonths() method in Java

Daniol Thomas

Daniol Thomas

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

163 Views

The number of months for a particular Period can be obtained using the getMonths() method in the Period class in Java. This method requires no parameters and it returns the number of months in the Period.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo { ... Read More

Period getYears() method in Java

Daniol Thomas

Daniol Thomas

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

234 Views

The number of years for a particular Period can be obtained using the getYears() method in the Period class in Java. This method requires no parameters and it returns the number of years in the Period.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo { ... Read More

Period isZero() method in Java

Daniol Thomas

Daniol Thomas

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

155 Views

It can be checked if the days, months and years in the Period are zero or not using the isZero() method in the Period class in Java. This method requires no parameters. Also, it returns true if the days, months and years in the Period are zero and false otherwise.A ... Read More

Advertisements