Get Specific Object from Array of Objects in MongoDB Document

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

459 Views

To get specific object from array of objects, use positional operator($). Let us first create a collection with documents −> db.getASpecificObjectDemo.insertOne( ...   { ...      _id :1, f ...      "CustomerName" : "Larry", ...      "CustomerDetails" : { ...         "CustomerPurchaseDescription": [{ ...            id :100, ...            "ProductName" : "Product-1", ...            "Amount":10000 ...         }, { ...               id :101, ...               "ProductName" : ... Read More

Create Dialog Box in Java with Yes, No and Cancel Buttons

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

2K+ Views

For a dialog box with Yes No Cancel buttons, you need to use the JOptionPane.showConfirmDialog(), wherein you will get a confirmation dialog box.The following is an example to create a dialog box in Java with Yes No and cancel buttons −Examplepackage my; import java.awt.Dimension; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.UIManager; public class SwingDemo {    public static void main(String[] args) {       ImageIcon icon = new ImageIcon("E −ew.PNG");       JPanel panel = new JPanel();       panel.setSize(new Dimension(250, 100));       panel.setLayout(null);       JLabel label1 = ... Read More

Get Last Days of All Months in MySQL

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

150 Views

To get the last days of all the months, use the LAST_DAY() function from MySQL −SELECT LAST_DAY(yourColumnName) from yourTableName;Let us first create a table −mysql> create table DemoTable    (    ShippingDate date    ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-12'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2019-02-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2019-03-04'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('2019-04-21'); Query OK, 1 row affected (0.14 sec)Display all records ... Read More

Set Auto Increment in a Table While Creating It in MySQL

Kumar Varma
Updated on 30-Jul-2019 22:30:26

213 Views

Let us first create a table. We have used AUTO_INCREMENT while creating the table to set auto increment for StudentId −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT,    -> StudentFirstName varchar(100),    -> StudentLastName varchar(100),    -> StudentAge int,    -> StudentCountryName varchar(100),    -> PRIMARY KEY(StudentId)    -> )AUTO_INCREMENT=30; Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentFirstName, StudentLastName, StudentAge, StudentCountryName) values('John', 'Smith', 21, 'US'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(StudentFirstName, StudentLastName, StudentAge, StudentCountryName) values('Chris', 'Brown', ... Read More

HTML DOM PopStateEvent Object

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

175 Views

The HTML DOM popStateEvent object is an event handler for the popstate event which occurs when window’s history changes.Property of PopStateEventPropertyExplanationstateIt returns an object that represents a copy of the history entries.ExampleLet us see an example of HTML DOM popStateEvent Object − Live Demo    html{       height:100%;    }    body{       text-align:center;       color:#fff;       background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;       height:100%;    }    p{       font-size:1.2rem;    }    .btn{       background:#0197F6;       border:none;   ... Read More

C++ Program for Finding Vertex, Focus and Directrix of a Parabola

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

197 Views

Here we will see how to find the vertex, focus directrix of a parabola using C or C++ program. To get these parameters we need the general equation of a parabola. The general formula is −𝑦 = 𝑎𝑥2 + 𝑏𝑥 + 𝑐The values of a, b and c are given.The formula for the vertex −The formula for the focus −The formula for the Directrix - y −Example Live Demo#include using namespace std; void getParabolaDetails(float a, float b, float c) {    cout

Automatically Generate Stacktrace When GCC C++ Program Crashes

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

2K+ Views

For Linux and we can use gcc to compile C/C++ codes. This compiler uses glibc library. We can use the backtrace() function to trace the error. This function is present inside the execinfo.h header file. In this example, we are going to display Segmentation fault error using the stack trace feature.Example#include #include #include #include #include using namespace std; void error_handler(int sig) {    void *array[10];    size_t size;    size = backtrace(array, 10); //get the void pointers for all of the entries    cout

Create FileFilter for JFileChooser in Java

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

1K+ Views

To create FileFilter, use the FileNamExtensionFilter class. The following is an example to display File Type in JFileChooser −Exampleimport javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; public class SwingDemo {    public static void main(String[] args) {       JFileChooser file = new JFileChooser();       file.setAcceptAllFileFilterUsed(false);       FileNameExtensionFilter extFilter = new FileNameExtensionFilter("JPEG file", "jpg", "jpeg");       file.addChoosableFileFilter(extFilter);       file.showOpenDialog(null);    } }Output

Create Android Notification with Longer Text

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

393 Views

This example demonstrate about How to create an Android notification with a longer textStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; public class MainActivity extends AppCompatActivity {    public static final String NOTIFICATION_CHANNEL_ID = "10001" ;    private final static String default_notification_channel_id ... Read More

Match Element in Array of MongoDB

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

324 Views

You can use $or operator along with limit(1) to match element in array. Let us first create a collection with documents −> db.matchElementInArrayDemo.insertOne( ...   { ...      "StudentName" : "Chris" , ...      "StudentOtherDetails" : ...      [ ...         {"StudentCountryName" : "US" , "StudentSkills" : "MongoDB"}, ...         {"StudentCountryName" : "UK" , "StudentSkills" : "Java"} ...       ] ...   } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd423282cba06f46efe9ee2") } > db.matchElementInArrayDemo.insertOne( ...   { ...      "StudentName" : "Chris" , ...   ... Read More

Advertisements