Search for documents matching first item in an array with MongoDB?

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

74 Views

Let us first create a collection with documents −> db.matchingFirstItemInTheArrayDemo.insertOne(    {       "ClientDetails": [          {             "ClientName": "Larry",             "ClientAge":28          }       ]    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7a5d26d78f205348bc636") } > db.matchingFirstItemInTheArrayDemo.insertOne( {    "ClientDetails": [       {          "ClientName": "Chris",          "ClientAge":56,       }    ] } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7a5f56d78f205348bc637") } > db.matchingFirstItemInTheArrayDemo.insertOne( ... Read More

HTML Tag

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

122 Views

The tag is used to define the keyboard input. Use this when you want the user to type on their keyboard, for example, shortcut keys Ctrl+C for copy, Esc for exit, etc. Let us now see an example to implement the tag −Example Live Demo Shortcut Keys    Use the following shortcut keys −    Cut − CTRL+X    Copy − CTRL+C    Paste − CTRL+V    Undo − CTRL+Z OutputIn the above example, we have set some shortcut keys −Cut − CTRL+XThe shortcut key is set using the element, for example, CTRL + X :CTRL+X

HTML DOM Location origin Property

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

55 Views

The Location origin property returns the string corresponding to the URL’s protocol, hostname, host port number (if specified).SyntaxFollowing is the syntax −Returning value of the origin propertylocation.originExampleLet us see an example for Location origin property − Live Demo Location origin    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } Location-origin Current URL:    var divDisplay = document.getElementById("divDisplay");    var urlSelect = document.getElementById("urlSelect");    function getorigin(){       divDisplay.textContent = 'URL Origin: '+location.origin;    } OutputThis will produce the following output −Before clicking ‘Get origin’ button −After clicking ‘Get origin’ button −

How to launch a program using C++ program?

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

2K+ Views

Here we will see how to start some third-party application like notepad or anything using C++ program. This program is very simple, we can use command prompt command to do this task.We will pass the application name inside the system() function. This will open it accordingly.Example#include using namespace std; int main() {    cout >> "Opening Nodepad.exe" >> endl;    system("notepad.exe"); }Output

How to find Segmentation Error in C & C++ ? (Using GDB)

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

1K+ Views

The segmentation error is one of the runtime error, that is caused because of the memory access violation, like accessing invalid array index, pointing some restricted address etc. In this article, we will see how to detect this type of error using the GDB tool.Let us see the code and respective steps to locate the error.Example#include main() {    int* ptr = NULL;    *ptr = 1; //trying to access unknown memory location    printf("%p", ptr); }Compile the code using ‘gcc –g program_name.c’, and run using ‘./a.out’Outputsoumyadeep@soumyadeep-VirtualBox:~/Cpp_progs$ ./a.out Segmentation fault (core dumped)The segmentation error occurred.Write ‘gdb ./a.out core’soumyadeep@soumyadeep-VirtualBox:~/Cpp_progs$ gdb ... Read More

How to add button to notifications in android?

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

2K+ Views

This example demonstrate about How to add button to notifications in androidStep 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.app.PendingIntent ; import android.content.Intent ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity {    public static final String NOTIFICATION_CHANNEL_ID = "10001" ... Read More

How to prepend string to entire column in MongoDB?

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

111 Views

Prepend string to entire column in MongoDB using aggregate framework. Let us first create a collection with documents −> db.prependDemo.insertOne({"StudentFirstName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccf3bcedceb9a92e6aa1955") } > db.prependDemo.insertOne({"StudentFirstName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccf3bd3dceb9a92e6aa1956") } > db.prependDemo.insertOne({"StudentFirstName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccf3bd8dceb9a92e6aa1957") }Following is the query to display all documents from a collection with the help of find() method −> db.prependDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccf3bcedceb9a92e6aa1955"), "StudentFirstName" : "John" } {    "_id" : ObjectId("5ccf3bd3dceb9a92e6aa1956"),    "StudentFirstName" : "Chris" } {    "_id" : ObjectId("5ccf3bd8dceb9a92e6aa1957"), ... Read More

What is the difference between Math.ceil() and Math.round() methods in JavaScript?

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

4K+ Views

Math.ceil() and Math.round() methods differ in a way that the former round off a number to its nearest integer in upward direction of rounding(towards the greater value) whereas the latter round off a number to its nearest integer in downward direction of rounding(towards lower value). Let's examine the two methods individually.Math.ceil()Math.ceil() method round off number passed as parameter to its nearest integer so as to get greater value.ExampleIn the below example when a number 5.34 passed as a parameter, Math.ceil() round off it in to 6, which is a greater value than actual number.Live Demo document.write(Math.ceil(5.34)); ... Read More

How to create a Box Layout in Java?

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

2K+ Views

To create a Box Layout in Java Swing, use the BoxLayout class. Here, we have also set that the components should be laid our left to right or top to bottom −Box box = new Box(BoxLayout.X_AXIS); box.add(button1); box.add(button2); box.add(button3); box.add(button4); box.add(Box.createGlue()); box.add(button5); box.add(button6); box.add(button7); box.add(button8);Above, we have 8 buttons in our Box Layout. We have separated 4 buttons each using the createGlue() method.The following is an example to create a BoxLayout in Java −Examplepackage my; import java.awt.BorderLayout; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo {    public static void main(String args[]) {     ... Read More

MySQL query to decrease value by 10 for a specific value?

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

465 Views

Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Score int    ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score) values(67); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Score) values(78); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Score) values(90); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Score) values(56); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----+-------+ ... Read More

Advertisements