MongoDB Query for Fields in Embedded Document

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

266 Views

Let us first create a collection with documents −> db.embeddedDocumentDemo.insertOne( ...    { ...       "CustomerDetails":[ ...          {"CustomerName":"Chris", "CustomerPurchasePrice":3000}, ...          {"CustomerName":"Robert", "CustomerPurchasePrice":4500}, ...          {"CustomerName":"David", "CustomerPurchasePrice":1000}, ...       ] ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd32347edc6604c74817ccd") }Following is the query to display all documents from a collection with the help of find() method −> db.embeddedDocumentDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd32347edc6604c74817ccd"),    "CustomerDetails" : [       {          "CustomerName" ... Read More

Push New Items to an Array Inside an Object in MongoDB

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

975 Views

You can use $elemMatch operator for this. Let us first create a collection with documents −> db.pushNewItemsDemo.insertOne(    {       "_id" :1,       "StudentScore" : 56,       "StudentOtherDetails" : [          {             "StudentName" : "John",             "StudentFriendName" : [                "Bob",                "Carol"             ]          },          {             "StudentName" : ... Read More

HTML Input Min Attribute

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

161 Views

The min attribute of the element is used to set the minimum value for . Both min and max are used to set a range of value for input element with type number, date, datetime, range, etc. It introduced in HTML5.Let us now see an example to implement the min attribute of the element. Here, we have set min as 1, therefore a user cannot enter an ID less than 1−Example Live Demo Log in to your account Id: Password: DOB: ... Read More

Calculate Area of Octagon

Sharon Christine
Updated on 30-Jul-2019 22:30:26

887 Views

An octagon is a polygon with eight sides. To calculate the area of octagon the following formula is used, Area of octagon = ((a2*2) / *tan (22.5°)) = ((2*a*a)(1+√2))Code Logic, The area of a polygon with eight side is calculated by using the above formula. The expression uses sqrt function to find the square root of 2. The value of expression is evaluated as a floating point value that is put into the float area variable.Example Live Demo#include #include int main(){    int a = 7;    float area;    float multiplier = 6.18;    printf("Program to find area ... Read More

HTML DOM Input Date Required Property

AmitDiwan
Updated on 30-Jul-2019 22:30:26

180 Views

The HTML DOM Input Date required property determines whether Input date is compulsory to set or not.SyntaxFollowing is the syntax −Returning boolean value - true/falseinputDateObject.requiredSetting required to booleanValueinputDateObject.required = booleanValueBoolean ValuesHere, “booleanValue” can be the following −booleanValueDetailstrueIt defines that it is compulsory to set the date field to submit form.falseIt is the default value and to set date field is not compulsory.ExampleLet us see an example of Input Date required property − Live Demo Input Date required Name:  Date of Birth:  Confirm    var divDisplay = document.getElementById("divDisplay");    var inputDate = document.getElementById("dateSelect");    function submit() {   ... Read More

sqrt, sqrtl and sqrtf in C++

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

949 Views

In the cmath library of C++, there are different functions for getting the square root except from sqrt. The sqrt is used basically for double type input. The others are used for float, long type data etc. Let us see the usage of these functions.The sqrt() FunctionThis function is used for double type data. So this returns square root of type double. The syntax is like below.double sqrt(double argument)Example#include #include #include using namespace std; main() {    double x = 144.0;    double y = 180.0;    cout

Get All Table Names from a Database Using JDBC

Arushi
Updated on 30-Jul-2019 22:30:26

8K+ Views

You can get the list of tables in the current database in MySQL using the SHOW TABLES query.Show tables;Following JDBC program retrieves the list of tables in the database by executing the show tables query.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ListingTables {    public static void main(String args[]) throws Exception {       //Registering the Driver       DriverManager.registerDriver(new com.mysql.jdbc.Driver());       //Getting the connection       String mysqlUrl = "jdbc:mysql://localhost/mydatabase";       Connection con = DriverManager.getConnection(mysqlUrl, "root", "password");       System.out.println("Connection established......");       //Creating a Statement object ... Read More

Differences Between unshift and push Methods in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

Both the methods are used to  add elements to the array.But the only difference is unshift() method adds the element at the start of the array whereas push() adds the element at the end of the array.1) push()Array.push() method is used to add an element at the end of an array like a queue .In the following example it is shown how to add an element using push() method Live DemoExample var cars = ["Benz", "Lamborghini", "Tata safari"]; cars.push("Ferrari"); document.write(cars); OutputBenz, Lamborghini, Tata safari, Ferrari2)  unshift()Array.unshift() method is ... Read More

Center Components Using FlowLayout in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:26

227 Views

Use FlowLayout.CENTER to lay out components in a flow to be centered with FlowLayout. The following is an example to lay out components in a flow to be centered with FlowLayout −Examplepackage my; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("WorldCup2019");       frame.setLayout(new FlowLayout(FlowLayout.CENTER));       JLabel label = new JLabel("WorldCup Hosting Country ");       label.setPreferredSize(new Dimension(220, 70));       label.setOpaque(true);       label.setBackground(Color.ORANGE);     ... Read More

Select Where Sum of Fields is Greater Than a Value in MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:26

345 Views

You can use $where operator for this. Let us first create a collection with documents −> db.sumOfFieldIsGreaterThanDemo.insertOne({"Price1":10, "Price2":50, "Price3":40}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd84b8bf3115999ed511e6") } > db.sumOfFieldIsGreaterThanDemo.insertOne({"Price1":11, "Price2":1, "Price3":120}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd84c6bf3115999ed511e7") } > db.sumOfFieldIsGreaterThanDemo.insertOne({"Price1":10, "Price2":9, "Price3":6}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd84d2bf3115999ed511e8") }Following is the query to display all documents from a collection with the help of find() method −> db.sumOfFieldIsGreaterThanDemo.find();This will produce the following output −{ "_id" : ObjectId("5cdd84b8bf3115999ed511e6"), "Price1" : 10, "Price2" : 50, "Price3" : 40 } { "_id" : ObjectId("5cdd84c6bf3115999ed511e7"), "Price1" : ... Read More

Advertisements