You can remove an array element by its index using the following two steps −The first step is as follows −db.yourCollectionName.update({}, {$unset : {"yourArrayFieldName.yourIndexValue" : 1 }});The above syntax will put a null value at the location of ‘yourIndexValue’. After that, you need to pull the null value from array filed to remove from an array element.The second step is as follows −db.yourCollectionName.update({}, {$pull : {"yourArrayFieldName" : null}});To implement the syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.removeArrayElementByItsIndexDemo.insertOne({"InstructorName":"David", "InstructorAge":28, "InstructorSubject":["MongoDB", "MySQL", "Java", "SQL Server", ... Read More
MongoDB order the docs in one collection with the help of a $natural operator. It stores the document as it is when we get from find(). The default order is $natural. Let us now see the syntax −db.yourCollectionName.find().sort({ "$natural": 1 });To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.orderDocsDemo.insertOne({"UserScore":87}); { "acknowledged" : true, "insertedId" : ObjectId("5c9531a316f542d757e2b44b") } > db.orderDocsDemo.insertOne({"UserScore":98}); { "acknowledged" : true, "insertedId" : ObjectId("5c9531a816f542d757e2b44c") } > db.orderDocsDemo.insertOne({"UserScore":99}); { "acknowledged" : true, "insertedId" : ObjectId("5c9531b216f542d757e2b44d") ... Read More
To get the max value, use the max() function. Let us create a table first −mysql> create table findMaxValueInVarcharField -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Value varchar(200) -> ); Query OK, 0 rows affected (1.09 sec)Following is the query to insert some records in the table using insert command −mysql> insert into findMaxValueInVarcharField(Value) values('200'); Query OK, 1 row affected (0.14 sec) mysql> insert into findMaxValueInVarcharField(Value) values('1000'); Query OK, 1 row affected (0.25 sec) mysql> insert into findMaxValueInVarcharField(Value) values('899474'); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More
To rotate a list in Java, let us first create a List and add elements −List < Integer > list = new ArrayList < Integer > (); list.add(5); list.add(10); list.add(15); list.add(20); list.add(25); list.add(30); list.add(35); list.add(40); list.add(45);Now, rotate the list −Collections.reverse(list);Example Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) { Listlist = new ArrayList(); list.add(5); list.add(10); list.add(15); list.add(20); list.add(25); list.add(30); list.add(35); list.add(40); list.add(45); ... Read More
To extract the User ID only from MySQL, you can use SUBSTRING_INDEX(), which extracts the part of a string from the Username to get the User ID. Let us first display the user −mysql> SELECT USER();This will produce the following output −+----------------+ | USER() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)Let us now extract the UserID only −mysql> SELECT SUBSTRING_INDEX(USER(), '@', 1);This will produce the following output −+-------------------------------+ | SUBSTRING_INDEX(USER(), '@', 1) | +-------------------------------+ | root ... Read More
Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How append string with select command in Android sqliteStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details ... Read More
First, you need to open my.cnf file. The following is the query to get the directory location of the config file on Windows −mysql> select @@datadir;Output+---------------------------------------------+ | @@datadir | +---------------------------------------------+ | C:\ProgramData\MySQL\MySQL Server 8.0\Data\ | +---------------------------------------------+ 1 row in set (0.00 sec)Here is the snapshot of the directory −Now open my.cnf file. The snapshot is as follows −If you want to add more data to cache, ... Read More
This example demonstrates about How to get city information from Network provider 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 a text view to show city information.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.Manifest; import android.content.pm.PackageManager; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; ... Read More
This example demonstrate about How to use equals () in Android textview.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 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken name as Edit text, when user click on button it will take data and check that given string contains “point”.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; ... Read More
Before getting into an example, we should know what SQLite database in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built-in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrates How to use smallint value in Android SQLite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a ... Read More