Get Array of IDs in MongoDB

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

767 Views

The _id in MongoDB is a field, which is mandatory. In MongoDB, each document stored in a collection requires a unique _id field that acts as a primary key. Following is the syntax to get the array of all the ids i.e. _id in MongoDBdb.yourCollectionName.find({ _id : { $in : [yourValue1, yourValue2, yourValue3, .......N] } } );Let us first implement the following query to create a collection with documents> db.selectInWhereIdDemo.insertOne({"_id":23}); { "acknowledged" : true, "insertedId" : 23 } > db.selectInWhereIdDemo.insertOne({"_id":28}); { "acknowledged" : true, "insertedId" : 28 } > db.selectInWhereIdDemo.insertOne({"_id":45}); { "acknowledged" : true, "insertedId" : 45 } > db.selectInWhereIdDemo.insertOne({"_id":75}); ... Read More

MySQL Query to Count Rows with Specified Values

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

85 Views

To get the count of rows in which two or more specified values appear, let us first create a sample table:mysql> create table specifiedValuesDemo -> ( -> Value int, -> Value2 int, -> Value3 int -> ); Query OK, 0 rows affected (0.60 sec)Following is the query to insert some records in the table using insert command:mysql> insert into specifiedValuesDemo values(10, 15, 20); Query OK, 1 row affected (0.17 sec) mysql> insert into specifiedValuesDemo values(40, 10, 20); Query OK, 1 row affected (0.16 sec) ... Read More

Find Basis and Dimension of a Matrix in C++

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

242 Views

This is a C++ program to find Basis and Dimension of a Matrix.AlgorithmBegin    Function determinant() :    It calculates determinant of the matrix.    /*       Arguments:       n = number of elements.       matrix[10][10] = input matrix.    */    declare the submatrix submatrix[10][10].    //Body of the function:    if (n == 2)       return ((matrix[0][0] * matrix[1][1]) - (matrix[1][0] * matrix[0][1]))    else       Make a for loop c = 0 to n-1          Declare and initialize submati = 0, submatj.     ... Read More

Embed YouTube as an Audio Player

Anuradha Nanda
Updated on 30-Jul-2019 22:30:25

1K+ Views

Wanna use YouTube on your website as an audio player?Piece of cake.Generating the Embed CodeWatching a YouTube video is fun, but there are times when we just want the audio of a video rather than watching the whole video. The main advantage of embedding YouTube videos as an audio player is that it saves a lot of data, as we can also play the music in the background without keeping the display active all the time.Step 1: The first thing you have to do is go to the page of the video that you need to embed and click on ... Read More

Clock tickSeconds Method in Java

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

190 Views

The current ticking with the system clock in seconds can be obtained using the method tickSeconds() in the Clock Class in Java. This method requires a single parameter i.e. the time zone and it returns the current ticking value in seconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { ZoneId zone = ZoneId.of("Australia/Melbourne"); Clock c = Clock.tickSeconds(zone); System.out.println("The current ticking value in seconds is: " + ... Read More

What is a Pair Class in Java Tuples

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

196 Views

A Pair class in JavaTuples can only have 2 elements. The JavaTuples library includes the Pair class.The following is the declaration −public final class Pair extends Tuple implements IValue0, IValue1Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Some of its features include −TypesafeSerializableComparableIterableImmutableNote − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples ... Read More

Types of JDBC Drivers

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

1K+ Views

There are 4 types of JDBC drivers namely, Type-1, Type-2, Type-3 and, Type-4.Type1 It is the ODBC − JDBC bridge driver, it acts as a bridge between JDBC and, ODBC database connectivity mechanism. Using this you can access the databases which support only ODBC. Initially, it is used extensively, since most of the databases supported only ODBC.Whenever Java application sends a request to the JDBC-ODBC bridge driver the request internally calls the ODBC equivalent function and the ODBC driver retrieves the result from the underlying database and sends it back to the JDBC-ODBC bridge driver.Advantages of type1 driverFollowing are the advantages ... Read More

Get Root Directory Information in Android

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

3K+ Views

This example demonstrate about How to get root directory information in android.Step 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. In the above code, we have taken text view to show root directory.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.KeyguardManager; import android.content.Context; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkInfo; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class MainActivity extends AppCompatActivity { ... Read More

ArrayBlockingQueue Remove Method in Java

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

149 Views

The remove() method of the ArrayBlockingQueue class in Java is used to remove a single instance of the specified element from this queue.The syntax is as followsboolean remove(Object ele)Here, ele is the element to be removed from the queue. To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement remove() method of Java ArrayBlockingQueue classExample Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(120);       q.add(10);   ... Read More

Convert Timestamp Object to Date in JDBC Program

Nitya Raut
Updated on 30-Jul-2019 22:30:25

623 Views

The getTime() method of the Timestamp class retrieves and returns the time from the current timestamp in milliseconds (long) from epoch time 1, 1970 00:00:00.000 GMT.Timestamp timestamp = rs.getTimestamp("DispatTimestamp"); long time = timestamp.getTime();The constructor of the java.sql.Date class accepts a long variable representing the time in milliseconds from the epoch time and constructs the date object.//Printing the date of dispatch System.out.println("Date of dispatch: "+new Date(time));Using these, you can convert a TimeStamp object to Date object in JDBC.Assume we have established connection with MySQL database and created a table named dispatch_data using statement object as://Creating a Statement object Statement stmt = ... Read More

Advertisements