Return Query Based on Date in MongoDB

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

329 Views

To return query based on the date in MongoDB, let us take an example.To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.returnQueryFromDate.insertOne({"PassengerName":"John", "PassengerAge":23, "PassengerArrivalTime":new ISODate("2018-03-10 14:45:56")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a57be9064dcd4a68b70e4") } > db.returnQueryFromDate.insertOne({"PassengerName":"Larry", "PassengerAge":21, "PassengerArrivalTime":new ISODate("2018-05-19 11:10:23")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a57bf9064dcd4a68b70e5") } > db.returnQueryFromDate.insertOne({"PassengerName":"Mike", "PassengerAge":24, "PassengerArrivalTime":new ISODate("2018-08-25 16:40:12")}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a57bf9064dcd4a68b70e6") } >db.returnQueryFromDate.insertOne({"PassengerName":"Carol", "PassengerAge":26, "PassengerArrivalTime":new ISODate("2019-01-29 09:45:10")}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a57bf9064dcd4a68b70e7") }Display all documents from a ... Read More

StringJoiner Class in Java 8

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

257 Views

The StringJoiner class in Java 8 constructs a sequence of characters. This sequence is separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix.The following are the constructors of the StringJoiner class:StringJoiner(CharSequence delimiter): This constructor constructs a StringJoiner with no characters in it and with no prefix or suffix. It used the copy of the supplied delimiter.StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix) This constructor constructs a StringJoiner with no characters in it. It uses the copies of the supplied prefix, delimiter and suffix.The syntax is as follows:public final class StringJoiner extends ObjectHere, class ... Read More

STL Priority Queue for Structure or Class in C++

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

655 Views

STL Priority Queue is the implementation of maxheap.This is a C++ program of STL priority queue for structure.AlgorithmBegin    Define a structure of type student.    Initialize variables in student structure.    Define another structure of type comparemarks    Overload the variables of student structure in comapremarks    structure.    Use priority queue with structure.    Insert some elements in priority queue using student structure.    While the queue is not empty do       Print the elements. End.Example Code Live Demo#include #include using namespace std; #define ROW 6 #define COL 3 struct student { //defining the student ... Read More

Use Namespaces in C++

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

218 Views

In this article we will see how to use the namespace in C++ code.Consider a situation, when we have two persons with the same name, Zara, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother’s or father’s name, etc.Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). ... Read More

Project Specific Fields from a Document in MongoDB

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

345 Views

To project specific fields from a document inside an array, you can use positional ($) operator.Let us first create a collection with documents> db.projectSpecificFieldDemo.insertOne(    ... {       ... "UniqueId": 101,       ... "StudentDetails" : [{"StudentName" : "Chris", "StudentCountryName ": "US"},          ... {"StudentName" : "Robert", "StudentCountryName" : "UK"},       ... ]       ... } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca27aeb6304881c5ce84ba2") } > db.projectSpecificFieldDemo.insertOne( { "UniqueId": 102, "StudentDetails" :    [{"StudentName" : "Robert", "StudentCountryName ": "UK"}, {"StudentName" : "David",    "StudentCountryName" : "AUS"}, ] ... Read More

Count Days Between Two Dates in Java

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

1K+ Views

Let us first set two dates:LocalDate date1 = LocalDate.of(2019, 4, 16); LocalDate date2 = date1.with(Month.MAY).withDayOfMonth(04);Now, count the dates between both the above dates using between():int numDays = Period.between(date1, date2).getDays();Exampleimport java.time.LocalDate; import java.time.Month; import java.time.Period; public class Demo {    public static void main(String[] argv) {       LocalDate date1 = LocalDate.of(2019, 4, 16);       LocalDate date2 = date1.with(Month.MAY).withDayOfMonth(04);       int numDays = Period.between(date1, date2).getDays();       System.out.println("Number of days between two dates = "+numDays);    } }OutputNumber of days between two dates = 18

Select Second Largest Record from a Table in MySQL

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

270 Views

Yes, we can select second largest record from a table without using LIMIT clause. Let us first see an example and create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (0.66 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(67); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(92); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(88); ... Read More

8086 Program for Selection Sort

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

1K+ Views

In this program we will see how to sort array elements in ascending order by using selection sort.Problem StatementWrite 8086 Assembly language program to sort the elements in a given array using selection sort technique. The array is started from memory offset 501. The size of the series is stored at memory offset 500.DiscussionIn the selection sort technique, in each phase we are taking the smallest number from the array, swap the smallest element with the first element inside the array. Then move to second position, and check for second highest number form the second position to the end of ... Read More

Validate an IP Address in C

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

8K+ Views

In this program we will see how to validate an IP address using C. The IPv4 addresses are represented in dot-decimal notation. There are four decimal numbers (all are ranging from 0 to 255). These four numbers are separated by three dots.An example of a valid IP is: 192.168.4.1To validate the IP address we should follow these stepsTokenize the string (IP address) using the dot “.” delimiterIf the sub strings are containing any non-numeric character, then return falseIf the number in each token is not in range 0 to 255, then return falseIf there are exactly three dots and four ... Read More

Read Form Data Using JSP

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

3K+ Views

JSP handles requests using getParameter() method to read simple parameters and getInputStream() method to read binary data stream coming from the client.Reading Form Data using JSPJSP handles form data parsing automatically using the following methods depending on the situation −getParameter(): You call request.getParameter() method to get the value of a form parameter.getParameterValues(): Call this method if the parameter appears more than once and returns multiple values, for example, checkbox.getParameterNames(): Call this method if you want a complete list of all parameters in the current request.getInputStream(): Call this method to read binary data stream coming from the client.Read More

Advertisements