You can use positional operator $ for this. Let us first create a collection with documents −> db.subElementQueryingDemo.insertOne( ... { ... "ClientName":"Chris", ... "Status": [ { "isMarried": true }, { "isMarried": false } ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5ccf28c9dceb9a92e6aa1953") }Following is the query to display all documents from a collection with the help of find() method −> db.subElementQueryingDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccf28c9dceb9a92e6aa1953"), "ClientName" : "Chris", "Status" : [ { ... Read More
You can use DATE_ADD() function with where clause for this. Let us first create a table −mysql> create table DemoTable ( ShippingDate date ); Query OK, 0 rows affected (0.54 sec)Note : The current date and time is as follows, we found using NOW() −mysql> select now(); +-----------------------+ | now() | +-----------------------+ | 2019-06-04 20 :43 :57 | +-----------------------+ 1 row in set (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-16'); Query OK, 1 ... Read More
When a class has two or more methods by the same name but different parameters, at the time of calling based on the parameters passed respective method is called (or respective method body will be bonded with the calling line dynamically). This mechanism is known as method overloading.Exampleclass Test{ public int division(int a, int b){ int result = a/b; return result; } public double division (float a, float b){ double result = a/b; ... Read More
The Location hostname property returns/sets the hostname for the URL path.SyntaxFollowing is the syntax −Returning value of the hostname propertylocation.hostnameValue of the hostname property setlocation.hostname = hostnameExampleLet us see an example for Location hostname property − Live Demo Location hostname form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } Location-hostname Current URL: var divDisplay = document.getElementById("divDisplay"); var urlSelect = document.getElementById("urlSelect"); function getHostname(){ divDisplay.textContent = 'Hostname: '+location.hostname; } OutputThis will produce the following output −Before clicking ‘Get Hostname’ button −After clicking ‘Get Hostname’ button −
The getopt() is one of the built-in C function that are used for taking the command line options. The syntax of this function is like below −getopt(int argc, char *const argv[], const char *optstring)The opstring is a list of characters. Each of them representing a single character option.This function returns many values. These are like below −If the option takes a value, then that value will be pointed by optarg.It will return -1, when no more options to procesReturns ‘?’ to show that this is an unrecognized option, it stores it to optopt.Sometimes some options need some value, If the ... Read More
You can use $setIntersection for this. Let us first create a collection with documents −> db.setInterSectionDemo.insertOne( ... {"_id":101, "Value1":[55, 67, 89]} ... ); { "acknowledged" : true, "insertedId" : 101 } > db.setInterSectionDemo.insertOne( ... {"_id":102, "Value2":[90, 45, 55]} ... ); { "acknowledged" : true, "insertedId" : 102 } > db.setInterSectionDemo.insertOne( ... {"_id":103, "Value3":[92, 67, 45]} ... ); { "acknowledged" : true, "insertedId" : 103 }Following is the query to display all documents from a collection with the help of find() method −> db.setInterSectionDemo.find().pretty();This will produce the following output −{ "_id" : 101, "Value1" : [ 55, 67, ... Read More
substr()substr() method extracts parts of a string, beginning at the character at the specified index, and returns the specified number of characters. It does not change the original string. Syntaxsubstr() method accepts two parameters one is start and other is length str.substr(start , length)Arguments a) Start: start defines the starting index from where the sub string is to be extracted from the base string. b) length: length defines the number of characters to be extracted starting from the start in the given string. If the second argument to the function is ... Read More
To remove last char if it is a specific character then use SUBSTRING(). Let us first create a table −mysql> create table DemoTable ( SubjectName varchar(100) ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('MySQL'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('MongoDB?'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Java?'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('C'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select ... Read More
The width attribute of the element is only used with image and allows you to set the width of the image added using −The width attribute introduced in HTML5 and acts as the submit button. Following is the syntax −Above, width represents the width in pixels.Let us now see an example to implement the width attribute of the element wherein the width is set for input type image −Example Live Demo Register Id − Password − DOB − Telephone − Email − ... Read More
The read() method of the input stream classes reads the contents of the given file byte by byte and returns the ASCII value of the read byte in integer form. While reading the file if it reaches the end of the file this method returns -1.ExampleAssume we have a text file (sample.txt) in the current directory with a simple text saying “Hello welcome”. Following Java program reads the contents of the file byte by byte using the read() method and prints the integer value returned for each byte.Since we are not checking for end of the file, the read() method ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP