- 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
677 Views
You can use CONCAT() function for this. Let us first create a table −mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(100) ); Query OK, 0 rows affected (0.43 sec)Insert records in the table using insert command −mysql> insert into DemoTable(UserName) values('John'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(UserName) values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(UserName) values('Robert'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+----------+ ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
87 Views
Yes, you can use GREATEST() from MySQL to check maximum from rows (not columns). Let us first create a table −mysql> create table DemoTable ( Value1 int, Value2 int, Value3 int ); Query OK, 0 rows affected (0.58 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(190, 395, 322); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output−+--------+--------+--------+ | Value1 | Value2 | Value3 | +--------+--------+--------+ | 190 | 395 ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
209 Views
You can use length() from MySQL to find the size of text stores in a specific column. Let us first create a tablemysql> create table DemoTable ( CustomerName longtext ); Query OK, 0 rows affected (0.67 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output−+--------------+ | CustomerName | +--------------+ | Robert | +--------------+ 1 row in set (0.00 sec)Here is the query to find the size ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
You can use IF() for this. Let us first create a table. One of the columns here is having ENUM typemysql> create table DemoTable ( UserId int, UserName varchar(40), UserGender ENUM('M', 'F') ); Query OK, 0 rows affected (1.11 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(1, 'John', 'M'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(2, 'Maria', 'F'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(3, 'David', 'M'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(4, 'Emma', ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
240 Views
Let us first create a collection with documents −> db.arrayContainOnlySpecificFieldDemo.insertOne( ... { ... "StudentName":"John", ... "StudentAge":21, ... "StudentTechnicalSubject":["C", "Java", "MongoDB"] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cc4921dac184d684e3fa26a") } > db.arrayContainOnlySpecificFieldDemo.insertOne( { "StudentName":"Carol", "StudentAge":23, "StudentTechnicalSubject":["MongoDB"] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cc49237ac184d684e3fa26b") }Display all documents from a collection with the help of find() method. The query is as follows −> db.arrayContainOnlySpecificFieldDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cc4921dac184d684e3fa26a"), "StudentName" : "John", "StudentAge" : 21, ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
927 Views
To get attribute list from MongoDB object, you can use for loop to extract key and value for document. Let us create a collection with documents −>db.getAttributeListDemo.insertOne({"StudentId":101, "StudentName":"John", "StudentAdmissi onDate":new ISODate('2019-01-12'), "StudentSUbjects":["MongoDB", "Java", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cbdfcc9ac184d684e3fa269") }Display all documents from a collection with the help of find() method −> db.getAttributeListDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cbdfcc9ac184d684e3fa269"), "StudentId" : 101, "StudentName" : "John", "StudentAdmissionDate" : ISODate("2019-01-12T00:00:00Z"), "StudentSUbjects" : [ "MongoDB", "Java", "MySQL" ] }Following is the ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
87 Views
You can use findOne() for this. Following is the syntax −db.yourCollectionName.findOne({yourFieldName: 'yourValue'});Let us create a collection with documents −> db.checkExistingDemo.insertOne({"StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5cbdf90dac184d684e3fa265") } > db.checkExistingDemo.insertOne({"StudentName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5cbdf912ac184d684e3fa266") } > db.checkExistingDemo.insertOne({"StudentName":"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5cbdf916ac184d684e3fa267") } > db.checkExistingDemo.insertOne({"StudentName":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5cbdf91bac184d684e3fa268") }Display all documents from a collection with the help of find() method −> db.checkExistingDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cbdf90dac184d684e3fa265"), "StudentName" : "John" } { "_id" : ObjectId("5cbdf912ac184d684e3fa266"), "StudentName" : "Carol" } ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
191 Views
Yes, Mongo shell treats numbers as float by default. To work it as int or any other type, you need to mention explicitly. You can use NumberInt() for this. The syntax is as follows −var anyVariableName= [NumberInt("yourValue1"), NumberInt("yourValue2"), .....N];Let us implement the above syntax in order to treat numbers as integer only (not float) −> var integerArrayDemo = [NumberInt("50"), NumberInt("60"), NumberInt("70"), NumberInt("90"), NumberInt("40")];Following is the query to display the array value −> printjson(integerArrayDemo);This will produce the following output −[ NumberInt(50), NumberInt(60), NumberInt(70), NumberInt(90), NumberInt(40) ]To display the array value, you can use print() −> ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
In order to convert NumberLong to String in MongoDB, you can use toString() −NumberLong('yourValue').valueOf().toString();To convert NumberLong to String, you can use valueOf() as well −NumberLong('yourValue').valueOf();Let us implement both the above syntaxes.Following is the query to convert NumberLong to String with toString() −> NumberLong('1000').valueOf().toString();This will produce the following output −1000Following is the query to convert NumberLong to Number with valueOf()> NumberLong('1000').valueOf();This will produce the following output −1000
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
701 Views
You can use printjson() or print() to get output of MongoDB shell script. Let us create an array of objects.Following is the query to create an array of objects.> var studentDetails=[{"StudentName":"John","StudentAge":21}, {"StudentName":"Carol","StudentAge":24},{"StudentName":"David","StudentAge":25}];Following is the query to get the output of Mongo shell script using printjson() −> printjson(studentDetails);This will produce the following output −[ { "StudentName" : "John", "StudentAge" : 21 }, { "StudentName" : "Carol", "StudentAge" : 24 }, { "StudentName" : "David", "StudentAge" : 25 } ] > var studentDetails=[{"StudentName":"John","StudentAge":21}, {"StudentName":"Carol","StudentAge":24},{"StudentName":"David","StudentAge":25}];