- 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
Nishtha Thakur has Published 564 Articles
Nishtha Thakur
136 Views
For this, you can use $elemMatch operator. The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria. Let us first create a collection with documents −> db.filterBySeveralElementsDemo.insertOne( "_id":100, "StudentDetails": [ { ... Read More
Nishtha Thakur
137 Views
You can use DEFAULT CURRENT_TIMESTAMP. Keep in mind that it will work only at the time of insertion. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Arrivaltime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); Query OK, 0 rows affected ... Read More
Nishtha Thakur
226 Views
You can use positional operator $. Let us first create a collection with documents −> db.replaceAnArrayFieldValueDemo.insertOne({"StudentTechnicalSubjects":["MySQL", "SQL Server", "PL/SQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cea41e0ef71edecf6a1f68f") }Following is the query to display all documents from a collection with the help of find() method −> db.replaceAnArrayFieldValueDemo.find().pretty();This will produce the ... Read More
Nishtha Thakur
2K+ Views
To search exact word from string, use the below syntax −select *from yourTableName where yourColumnName regexp '(^|[[:space:]])yourWord([[:space:]]|$)';Let us first create a table −mysql> create table DemoTable ( Title text ); Query OK, 0 rows affected (0.23 sec)Insert some records in the table using insert command −mysql> insert ... Read More
Nishtha Thakur
2K+ Views
To build query dynamically, you need to write some script. Let us first create a collection with documents −> db.dynamicQueryDemo.insertOne({"Name":"John", "Subject":["MongoDB", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef5c5def71edecf6a1f69a") } > db.dynamicQueryDemo.insertOne({"Name":"John", "Subject":["C", "C++"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef5c73ef71edecf6a1f69b") } ... Read More
Nishtha Thakur
59 Views
The getMaxCharLiteralLength() method of the DatabaseMetaData interface is used to find out the maximum number of characters that the underlying database allows for a character literal.This method returns an integer value, representing the maximum length of a character literal. If this value is 0 it indicates that there is no ... Read More
Nishtha Thakur
99 Views
You can use CONCAT() function for this. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value1 varchar(10), Value2 varchar(10) ); Query OK, 0 rows affected (0.21 sec)Insert some records in the table using insert command ... Read More
Nishtha Thakur
236 Views
To query all items, use find(). Let us first create a collection with documents −> db.queryAllItemsDemo.insertOne({"StudentDetails":{"StudentName":"John", "StudentSubject":["MongoDB", "MySQL"], "StudentSubjectPrice":[4000, 6000]}, "OtherDetails":{"UserAge":29, "UserCountryName":"US"}}); { "acknowledged" : true, "insertedId" : ObjectId("5cef74ecef71edecf6a1f69f") }Display all documents from a collection with the help of find() method −> db.queryAllItemsDemo.find().pretty();This will produce the following output ... Read More
Nishtha Thakur
192 Views
You need to use OR condition along with WHERE clause. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, MonthNumber int, YearNumber int ); Query OK, 0 rows affected (0.22 sec)Insert some records in the table ... Read More
Nishtha Thakur
904 Views
To count number of elements in an array, use the aggregate framework. Let us first create a collection with documents −>db.countNumberOfElementsDemo.insertOne({"UserMessage":["Hi", "Hello", "Bye", "Awesome"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef8ec2ef71edecf6a1f6a1") }Display all documents from a collection with the help of find() method −> db.countNumberOfElementsDemo.find().pretty();This will produce the ... Read More