Achieve a Slice Chain in MongoDB

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

151 Views

Yes, you can achieve this using aggregate framework. Let us first create a collection with documents −> db.sliceOfSliceDemo.insertOne( ...    { ...       "Name": "John", ...       "Details": [["First 1:1", "First 1:2"], ["second 2:1", "Second 2:2"]] ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccf3fcfdceb9a92e6aa195a") }Following is the query to display all documents from a collection with the help of find() method −> db.sliceOfSliceDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5ccf3fcfdceb9a92e6aa195a"),    "Name" : "John",    "Details" : [       [          "First ... Read More

Make a Class Thread-Safe in Java

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

1K+ Views

A thread-safe class is a class that guarantees the internal state of the class as well as returned values from methods, are correct while invoked concurrently from multiple threads.The HashMap is a non-synchronized collection class. If we need to perform thread-safe operations on it then we must need to synchronize it explicitly.Example:import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.Iterator; public class HashMapSyncExample {    public static void main(String args[]) {       HashMap hmap = new HashMap();       hmap.put(2, "Raja");       hmap.put(44, "Archana");       hmap.put(1, "Krishna");       ... Read More

Convert Column to Case-Sensitive Collation in MySQL

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

621 Views

For this, you can use COLLATE. Following is the syntax −select *from yourTableName where yourColumnName LIKE yourValue COLLATE utf8_bin;Let us first create a table −mysql> create table DemoTable    (    LastName varchar(100)    ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('BROWN'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('brown'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('BRoWN'); Query OK, 1 row affected (0.14 sec)Display all records ... Read More

Cast Byte Object to Double Value in Java

Venkata Sai
Updated on 30-Jul-2019 22:30:26

959 Views

Java provides various datatypes to store various data values. It provides 7 primitive datatypes (stores single values) namely, boolean, byte, char, short, int, long, float, double and, reference datatypes (arrays and objects).Casting in JavaConverting one primitive data type into another is known as type casting. There are two types of casting −Widening− Converting a lower datatype to a higher datatype is known as widening. It is done implicitly.Narrowing− Converting a higher datatype to a lower datatype is known as narrowing. You need to do it explicitly using the cast operator (“( )”).For every primitive variable a wrapper class is available, ... Read More

C++ Program to Concatenate a String Given Number of Times

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

628 Views

Here we will see how we can concatenate a string n number of times. The value of n is given by the user. This problem is very simple. In C++ we can use + operator for concatenation. Please go through the code to get the idea.AlgorithmconcatStrNTimes(str, n)begin    res := empty string    for i in range 1 to n, do       res := concatenate res and res    done    return res endExample Live Demo#include using namespace std; main() {    string myStr, res = "";    int n;    cout > myStr;    cout > n;    for(int i= 0; i < n; i++) {       res += myStr;    }    cout

HTML DOM Location Port Property

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

130 Views

The Location port property returns/sets the port number (if specified) for a URL. Port number might not get displayed if not explicitly specified.SyntaxFollowing is the syntax −Returning value of the port propertylocation.portValue of the port property setlocation.port = portNumberExampleLet us see an example for Location port property − Live Demo Location port    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } ... Read More

rint, rintf, and rintl Functions in C++

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

207 Views

Here we will see three functions. These functions are Rint(), rintf() and the rintl(). These functions are used to convert floating point values into rounded format.The rint() FunctionThis function is used for rounding floating point value to integer. The syntax is like below. If the result is outside of return type, the domain error may occur. When the argument is 0 or infinity, then it will return unmodifiedfloat rint(float argument) double rint(double argument) long double rint(long double argument)Example#include #include using namespace std; main() {    double a, b, x, y;    x = 53.26;    y = 53.86; ... Read More

Start Android Activity from Notification Click

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

253 Views

This example demonstrate about How to start an Android activity when use clicks on NotificationStep 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 ... Read More

Implement Multiple Conditions in MongoDB

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

263 Views

Let us first create a collection with documents −> db.multipleConditionDemo.insertOne({"_id":1, "Name":"John"}); { "acknowledged" : true, "insertedId" : 1 } > db.multipleConditionDemo.insertOne({"_id":2, "Name":"Carol"}); { "acknowledged" : true, "insertedId" : 2 } > db.multipleConditionDemo.insertOne({"_id":3, "Name":"Sam"}); { "acknowledged" : true, "insertedId" : 3 } > db.multipleConditionDemo.insertOne({"_id":4, "Name":"David"}); { "acknowledged" : true, "insertedId" : 4 }Following is the query to display all documents from a collection with the help of find() method −> db.multipleConditionDemo.find().pretty();This will produce the following output −{ "_id" : 1, "Name" : "John" } { "_id" : 2, "Name" : "Carol" } { "_id" : 3, "Name" : "Sam" } { ... Read More

Understand StringBuffer and StringBuilder in Java

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

4K+ Views

StringBuffer(Thread-safe)StringBuffer is thread-safe meaning that they have synchronized methods to control access so that only one thread can access StringBuffer object's synchronized code at a time.StringBuffer objects are generally safe to use in a multi-threaded environment where multiple threads may be trying to access the same StringBuffer object at the same time.StringBuilder(Non-thread-safe)StringBuilder is not synchronized so that it is not thread-safe. By not being synchronized, the performance of StringBuilder can be better than StringBuffer.If we are working in a single-threaded environment, using StringBuilder instead of StringBuffer may result in increased performance. This is also true of other situations such as ... Read More

Advertisements