- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6702 Articles for Database
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
642 Views
To rename a collection in MongoDB, you can use renameCollection() method. The syntax is as follows −db.yourOldCollectionName.renameCollection('yourNewCollectionName');To understand the above syntax, let us list all the collections from database sample. The query is as follows −> use sample; switched to db sample > show collections;The following is the output −copyThisCollectionToSampleDatabaseDemo deleteDocuments deleteDocumentsDemo employee informationAboutDelete internalArraySizeDemo prettyDemo selectWhereInDemo sourceCollection updateInformation userInformationNow change collection name ‘informationAboutDelete’ to ‘deleteSomeInformation’. The query is as follows to change the collection name.> db.informationAboutDelete.renameCollection('deleteSomeInformation'); { "ok" : 1 }Here is the query to check the collection name has been renamed to 'deleteSomeInformation' −> show collections;The following is ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
818 Views
To aggregate sum in MongoDB to get the total count, you can use the $sum operator. To understand the above concept, let us create a collection with the document −> db.aggregateSumDemo.insertOne({"CustomerName":"Larry", "Amount":140}); { "acknowledged" : true, "insertedId" : ObjectId("5c8baa0680f10143d8431e18") } > db.aggregateSumDemo.insertOne({"CustomerName":"Mike", "Amount":160}); { "acknowledged" : true, "insertedId" : ObjectId("5c8baa1380f10143d8431e19") } > db.aggregateSumDemo.insertOne({"CustomerName":"Sam", "Amount":300}); { "acknowledged" : true, "insertedId" : ObjectId("5c8baa1c80f10143d8431e1a") } > db.aggregateSumDemo.insertOne({"CustomerName":"David", "Amount":500}); { "acknowledged" : true, "insertedId" : ObjectId("5c8baa2580f10143d8431e1b") }Display all documents from a collection with the help of find() method. The query is as follows −> db.aggregateSumDemo.find().pretty();The following ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
22K+ Views
Use the delete command to delete blank rows in MySQL.The syntax is as followsdelete from yourTableName where yourColumnName=' ' OR yourColumnName IS NULL;The above syntax will delete blank rows as well as NULL row.To understand the concept, let us create a table.The query to create a table is as followsmysql> create table deleteRowDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20) -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into deleteRowDemo(StudentName) values('John'); Query OK, 1 row affected ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
702 Views
You can check the current number of connections to MongoDB with the help of the following syntax −var anyVariableName= db.serverStatus(); yourVariableName.connections;The second syntax is as follows −db.serverStatus().connections;To understand both the above syntaxes, let us see them one by one −Case 1 − The first query is as follows −> var checkCurrentNumberOfConnections = db.serverStatus() > checkCurrentNumberOfConnections.connections;The following is the output −{ "current" : 1, "available" : 999999, "totalCreated" : 1 }Case 2 − The second query is as follows −> db.serverStatus().connectionsThe following is the output −{ "current" : 1, "available" : 999999, "totalCreated" : 1 }
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
782 Views
You can use $ne(not equal) operator for this. The syntax is as follows −db.yourCollectionName.find({yourFieldName: {$ne: true}}).pretty();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.queryForBooleanFieldsDemo.insertOne({"EmployeeName":"Larry", "EmployeeAge":24, "isOldEmployee":true}); { "acknowledged" : true, "insertedId" : ObjectId("5c8b7f7680f10143d8431e13") } > db.queryForBooleanFieldsDemo.insertOne({"EmployeeName":"Mike", "EmployeeAge":20, "isOldEmployee":false}); { "acknowledged" : true, "insertedId" : ObjectId("5c8b7f8680f10143d8431e14") } > db.queryForBooleanFieldsDemo.insertOne({"EmployeeName":"Sam", "EmployeeAge":23, "isOldEmployee":false}); { "acknowledged" : true, "insertedId" : ObjectId("5c8b7f9380f10143d8431e15") } > db.queryForBooleanFieldsDemo.insertOne({"EmployeeName":"David", "EmployeeAge":25, "isOldEmployee":true}); { "acknowledged" : true, "insertedId" : ObjectId("5c8b7fa280f10143d8431e16") } > db.queryForBooleanFieldsDemo.insertOne({"EmployeeName":"Carol", "EmployeeAge":27, "isOldEmployee":true}); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
The following is the code to create a database in MySQL from Java. We are creating the database with name, “Customer_Tracker_Database”import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class CreateDatabaseDemo { public static void main(String[] args) { Connection con=null; Statement stmt=null; String yourDatabaseName="Customer_Tracker_Database"; try { con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test3?useSSL=false", "root", "123456"); stmt = con.createStatement(); int status = stmt.executeUpdate("CREATE DATABASE "+yourDatabaseName); if(status > 0) { System.out.println("Database ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
94 Views
For returned record set order, you need to use FIND_IN_SET() function. For an example, let us create a table.mysql> create table returnRecordSetOrderDemo -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command.The query is as follows.mysql> insert into returnRecordSetOrderDemo values(100, 'John'); Query OK, 1 row affected (0.13 sec) mysql> insert into returnRecordSetOrderDemo values(130, 'Carol'); Query OK, 1 row affected (0.13 sec) mysql> insert into returnRecordSetOrderDemo values(103, 'Bob'); Query OK, 1 row affected (0.17 sec) mysql> insert into returnRecordSetOrderDemo values(134, 'Sam'); Query OK, ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
756 Views
Use any predefined function with select query or you can print some words with the select query in order to test connection with query.The syntax is as follows.SELECT yourValue;The select query with predefined function is as follows.The syntax is as follows.SELECT anyPredefinedFunctionName();Now you can implement the above syntax in order to test connection with query.Case 1 -The query is as follows.mysql> select "This is MySQL" as Display;The following is the output.+---------------+ | Display | +---------------+ | This is MySQL | +---------------+ 1 row in set (0.00 sec)Case 2 -The query is as follows.mysql> select ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
1K+ Views
You can use IN operator to select from one table that does not exist in another. To understand the above syntax, let us create a table.The first table name is A and second table name is B. The query to create a table is as followsmysql> create table A -> ( -> Value int -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command.The query is as followsmysql> insert into A values(10); Query OK, 1 row affected (0.23 sec) mysql> insert into A values(20); Query OK, 1 ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
111 Views
To select records having a given key, you can use $exists operator. The syntax is as follows −db.yourCollectionName.find( { yourFieldName: { $exists : true } } ).pretty();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.selectRecordsHavingKeyDemo.insertOne({"StudentName":"John", "StudentAge":21, "StudentMathMarks":78}); { "acknowledged" : true, "insertedId" : ObjectId("5c8b7be780f10143d8431e0f") } > db.selectRecordsHavingKeyDemo.insertOne({"StudentName":"Carol", "StudentMathMarks":89}); { "acknowledged" : true, "insertedId" : ObjectId("5c8b7bfc80f10143d8431e10") } > db.selectRecordsHavingKeyDemo.insertOne({"StudentName":"Sam", "StudentAge":26, "StudentMathMarks":89}); { "acknowledged" : true, "insertedId" : ObjectId("5c8b7c1280f10143d8431e11") } > db.selectRecordsHavingKeyDemo.insertOne({"StudentName":"Sam", "StudentMathMarks":98}); { "acknowledged" : true, ... Read More