Extract Subarray Value in MongoDB

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

433 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

Duration toHours Method in Java

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

209 Views

The value of a duration in the form of a number of hours can be obtained using the method toHours() in the Duration class in Java. This method does not require any parameters and it returns the duration in the form of a number of hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofDays(1); System.out.println("The duration is: " + d); System.out.println("Number of ... Read More

Iterate Through Septet Class in JavaTuples

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

127 Views

Like Arrays, we can also iterate through Septet class in JavaTuples using loops.Let us first see what we need to work with JavaTuples. To work with Septet class in JavaTuples, you need to import the following package −import org.javatuples.Septet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Septet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Septet; public class Demo {    public static void main(String[] args) {       ... Read More

Calculate Total Time Duration and Add Time in MySQL

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

2K+ Views

To calculate the total time duration in MySQL, you need to use SEC_TO_TIME(). Let us see an example by creating a tablemysql> create table AddTotalTimeDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > LoginTime time - > ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into AddTotalTimeDemo(LoginTime) values('05:05:00'); Query OK, 1 row affected (0.10 sec) mysql> insert into AddTotalTimeDemo(LoginTime) values('07:20:00'); Query OK, 1 row affected (0.16 sec) mysql> insert ... Read More

Difference Between JSP Forward and Response SendRedirect

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

383 Views

The element forwards the request object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file.sendRedirect sends HTTP temporary redirect response to the browser, and browser creates a new request to go the redirected page.

MonthDay withMonth Method in Java

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

120 Views

An immutable copy of a MonthDay with the month altered as required is done using the method withMonth() in the MonthDay class in Java. This method requires a single parameter i.e. the month that is to be set in the MonthDay and it returns the MonthDay with the month altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md1); ... Read More

Generate Infinite Stream of Double in Java Using DoubleStream.iterate

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

125 Views

The DoubleStream.iterate() returns an infinite sequential ordered DoubleStream produced by iterative application of a function f to an initial element seed, producing a Stream consisting of seed.The syntax is as followsstatic DoubleStream iterate(double seed, DoubleUnaryOperator f)Here, seed is the initial element and f is a function to be applied to the previous element to produce a new element.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to generate infinite stream of Double in Java with DoubleStream.iterate()Exampleimport java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { ... Read More

IntStream Parallel Method in Java

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

678 Views

The parallel() method of the IntStream class in Java returns an equivalent parallel stream. The method may return itself, either because the stream was already parallel, or because the underlying stream state was modified to be parallel.The syntax is as follows:IntStream parallel()Create an IntStream and you can use the range() method as well to set the range of elements:IntStream intStream = IntStream.range(20, 35);Now, use the parallel() method:intStream.parallel()The following is an example to implement IntStream parallel() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.range(20, 35);   ... Read More

Create a Nested Index in MongoDB

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

472 Views

To create nested index in MongoDB, you can use createIndex() or ensureIndex(). The syntax is as follows −db.yourCollectionName.createIndex({"yourOuterFieldName.yourInnerFieldName.yourSecondInnerFieldName": 1});To understand the syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.nestedIndexDemo.insertOne(    ... {       ...       ... "CustomerId":101,       ... "CustomerDetails":       ... {          ... "CustomerListDetails":          ... {             ... "CustomerName":"Larry",             ... "CustomerProjectName": "Project-1",           ... Read More

References in C++

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

293 Views

A reference variable is an alias, that is, another name for an already existing variable. Once a reference is initialized with a variable, either the variable name or the reference name may be used to refer to the variable.References vs PointersReferences are often confused with pointers but three major differences between references and pointers are −You cannot have NULL references. You must always be able to assume that a reference is connected to a legitimate piece of storage.Once a reference is initialized to an object, it cannot be changed to refer to another object. Pointers can be pointed to another ... Read More

Advertisements