Remove Array Element from MongoDB Collection Using Update and Pull

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

192 Views

Let us first create a collection with documents -> db.removingAnArrayElementDemo.insertOne({"UserMessage":["Hi", "Hello", "Bye"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef97bdef71edecf6a1f6a4") }Display all documents from a collection with the help of find() method -> db.removingAnArrayElementDemo.find().pretty();Output{    "_id" : ObjectId("5cef97bdef71edecf6a1f6a4"),    "UserMessage" : [       "Hi",       "Hello",       "Bye"    ] }Following is the query to remove an array element from MongoDB -> db.removingAnArrayElementDemo.update(    {_id:ObjectId("5cef97bdef71edecf6a1f6a4")},    { "$pull": { "UserMessage": "Hello" } } ); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })Let us check the document once again:> db.removingAnArrayElementDemo.find().pretty();Output{   ... Read More

Importance of Math.trunc() Method in JavaScript

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

165 Views

Math.trunc()Unlike Math.floor(), Math.ceil() and Math.round(), Math.trunc() method removes fractional part and gives out only integer part. It doesn't care about rounding the number to the nearest integer. It doesn't even notice whether the value is positive or negative. Its function is only to chop up the fractional part.syntaxMath.trunc(x);parameters - Math.trunc() takes a number as an argument and truncates the fractional part.In the following example, Math.trunc() method truncated the fractional values of the provided positive numbers.ExampleLive Demo var val1 = Math.trunc("1.414"); var val2 = Math.trunc("0.49"); var val3 = Math.trunc("8.9"); document.write(val1); ... Read More

Work with Auto-Incrementing Column in MySQL

Rama Giri
Updated on 30-Jul-2019 22:30:26

126 Views

To work with auto incrementing column, you can set it as AUTO_INCREMENT while creating the table.Let us first create a table. Here, we have set the Id field as column since that would be our auto increment column −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK,  0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName, LastName) values('John', 'Smith'); Query OK,  1 row affected (0.14 sec) mysql> insert into DemoTable(FirstName, LastName) values('Chris', 'Brown'); Query OK,  1 row affected (0.13 sec) mysql> insert into DemoTable(FirstName, LastName) values('Carol', 'Taylor'); Query OK,  1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----+-----------+----------+ | Id | FirstName | LastName | +----+-----------+----------+ | 1  | John  ... Read More

All Permutations of a String Using Iteration

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

851 Views

In this section we will see how to get all permutations of a string. The recursive approach is very simple. It uses the back-tracking procedure. But here we will use the iterative approach.All permutations of a string ABC are like {ABC, ACB, BAC, BCA, CAB, CBA}. Let us see the algorithm to get the better idea.AlgorithmgetAllPerm(str)begin    sort the characters of the string    while true, do       print the string str       i := length of str – 1       while str[i - 1] >= str[i], do          i := ... Read More

OpenCV Python Program to Blur an Image

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

615 Views

OpenCV is one of the best python package for image processing. Also like signals carry noise attached to it, images too contain different types of noise mainly from the source itself (Camera sensor). Python OpenCV package provides ways for image smoothing also called blurring. This is what we are going to do in this section. One of the common technique is using Gaussian filter (Gf) for image blurring. With this, any sharp edges in images are smoothed while minimizing too much blurring.Syntaxcv.GaussianBlur(src,  ksize,  sigmaX[,  dst[,  sigmaY[,  borderType=BORDER_DEFAULT]]] )Where−src – input imagedst – output imageksize – Gaussian kernel size[ height width]. If ksize ... Read More

Clear All Selections in Java Swing JList

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

679 Views

To clear all selections, use the List clearSelection() method in Java −JList list = new JList(sports); list.clearSelection();Above, the elements in Sports array is a String array −String sports[]= { "Cricket", "Football", "Hockey", "Rugby"};The following is an example to clear all selection in JList −Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame {    static JFrame frame;    static JList list;    public static void main(String[] args) {       frame = new JFrame("JList Demo");       SwingDemo s = new SwingDemo();       JPanel panel = new JPanel();       String sports[]= ... Read More

Check If a Notification is Visible or Canceled in Android

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

812 Views

This example demonstrate about How it is possible in Android to check if a notification is visible or canceledStep 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 ; public class MainActivity extends AppCompatActivity {    public static final ... Read More

Search an Array of Hashes in MongoDB

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

236 Views

Let us first create a collection with documents −> db.searchAnArrayDemo.insertOne({_id:1, "TechnicalDetails":[{"Language":"MongoDB"}]}); { "acknowledged" : true, "insertedId" : 1 } > db.searchAnArrayDemo.insertOne({_id:2, "TechnicalDetails":[{"Language":"MySQL"}]}); { "acknowledged" : true, "insertedId" : 2 } > db.searchAnArrayDemo.insertOne({_id:3, "TechnicalDetails":[{"Language":"MongoDB"}]}); { "acknowledged" : true, "insertedId" : 3 } > db.searchAnArrayDemo.insertOne({_id:4, "TechnicalDetails":[{"Language":"MongoDB"}]}); { "acknowledged" : true, "insertedId" : 4 } > db.searchAnArrayDemo.insertOne({_id:5, "TechnicalDetails":[{"Language":"Java"}]}); { "acknowledged" : true, "insertedId" : 5 }Following is the query to display all documents from a collection with the help of find() method −> db.searchAnArrayDemo.find().pretty();This will produce the following output −{ "_id" : 1, "TechnicalDetails" : [ { "Language" : "MongoDB" } ] } ... Read More

Set Row Height of a JTree with Java

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

488 Views

To set the row height of a JTree, use the setRowHeight() and as a parameter set the height in pixels −tree.setRowHeight(25);The following is an example to set the row height of a JTree with Java −package my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Project");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("App");       DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Website");       DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("WebApp");       node.add(node1); ... Read More

Projection Result as an Array of Selected Items in MongoDB

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

158 Views

Use the distinct() for this, since it finds the distinct values for a specified field across a single collection or view and returns the results in an array.Let us first create a collection with documents −> db.projectionListDemo.insertOne({"_id":"1", "Subject":["MongoDB", "MySQL", "Java"]}); { "acknowledged" : true, "insertedId" : "1" } > db.projectionListDemo.insertOne({"_id":"2", "Subject":["MongoDB", "C", "C++"]}); { "acknowledged" : true, "insertedId" : "2" } > db.projectionListDemo.insertOne({"_id":"3", "Subject":["Java", "Python"]}); { "acknowledged" : true, "insertedId" : "3" }Display all documents from a collection with the help of find() method −> db.projectionListDemo.find().pretty();Output{ "_id" : "1", "Subject" : [ "MongoDB", "MySQL", "Java" ] } { "_id" : ... Read More

Advertisements