
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AmitDiwan has Published 10744 Articles

AmitDiwan
184 Views
To add a document in an already created collection, use $push in MongoDB. Let us create a collection with documents −> db.demo177.insertOne( { "Id": "101", "details": [ { "StudentName": "Chris", "Scores": [67, 71, 74], "SubjectName": ["MySQL", "Java"] }, { "StudentName": "David", "Scores": ... Read More

AmitDiwan
625 Views
To get substring, use $substr in MongoDB. Let us create a collection with documents −> db.demo176.insertOne({"ProductName":"PRODUCT-1"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3843a09e4f06af551997ef") } > db.demo176.insertOne({"ProductName":"PRODUCT-102"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3843a69e4f06af551997f0") } > db.demo176.insertOne({"ProductName":"PRODUCT-105"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3843aa9e4f06af551997f1") }Display ... Read More

AmitDiwan
115 Views
To count only collections that match two fields, use count(). Let us create a collection with documents −> db.demo175.insertOne({"EmployeeName":"Bob", "isMarried":"YES"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3840969e4f06af551997e8") } > db.demo175.insertOne({"EmployeeName":"David", "isMarried":"NO"}); { "acknowledged" : true, "insertedId" : ObjectId("5e38409e9e4f06af551997e9") } > db.demo175.insertOne({"EmployeeName":"Mike", "isMarried":"YES"}); { "acknowledged" : ... Read More

AmitDiwan
117 Views
To evaluate one or more values, use $or along with find(). Let us create a collection with documents −> db.demo174.insertOne({"StudentName":"Chris", "CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e383c709e4f06af551997e5") } > db.demo174.insertOne({"StudentName":"David", "CountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5e383c779e4f06af551997e6") } > db.demo174.insertOne({"StudentName":"Bob", "CountryName":"AUS"}); { "acknowledged" ... Read More

AmitDiwan
189 Views
To limit the number of values in a field, use MongoDB $slice. Let us create a collection with documents −> db.demo173.insertOne({"ListOfValues":[10, 40, 100, 560, 700, 900]}); { "acknowledged" : true, "insertedId" : ObjectId("5e383a4f9e4f06af551997e4") }Display all documents from a collection with the help of find() method −> db.demo173.find().pretty();This will ... Read More

AmitDiwan
3K+ Views
To find a value in lowercase, use the toLowerCase() method in MongoDB. Use the method in find() to find the value in lowercase.Let us create a collection with documents −> db.demo172.insertOne({"SubjectName":"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3838ce9e4f06af551997e1") } > db.demo172.insertOne({"SubjectName":"mongodb"}); { "acknowledged" : true, ... Read More

AmitDiwan
257 Views
To re-map the fields of a MongoDB collection, use update() along with $rename. Let us first create a collection with documents −> db.demo171.insertOne( { "Name": "Chris", "Details": { "SubjectName": "MySQL", "CountryName": "US" } } ); { "acknowledged" : true, "insertedId" : ObjectId("5e3837 399e4f06af551997e0") }Display all documents from a ... Read More

AmitDiwan
393 Views
For this, use REPLACE() function and replace empty space with the character. Let us first create a table −mysql> create table DemoTable (Subject text); Query OK, 0 rows affected (0.86 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row ... Read More

AmitDiwan
410 Views
To re-format datetime in MySQL, you can use DATE_FORMAT(). MySQL gives in the format yyyy-mm-dd.Let us first create a table −mysql> create table DemoTable1558 -> ( -> EmployeeJoiningDate datetime -> ); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert command −mysql> ... Read More

AmitDiwan
756 Views
Let us first create a table −mysql> create table DemoTable -> ( -> Value int -> ); Query OK, 0 rows affected (1.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(25); Query OK, 1 row affected (0.11 sec) mysql> insert into ... Read More