Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Nishtha Thakur
Page 35 of 40
Clone a collection in MongoDB?
To clone a collection in MongoDB, you can use the forEach() method. Let us first create a collection with a document.The query to create a collection with a document is as follows −> db.studentInformation.insertOne({"StudentName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bc15780f10143d8431e21") } > db.studentInformation.insertOne({"StudentName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bc15e80f10143d8431e22") } > db.studentInformation.insertOne({"StudentName":"James"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bc17380f10143d8431e23") }Display all documents from a collection with the help of find() method. The query is as follows −> db.studentInformation.find().pretty();The following is the output −{ "_id" : ObjectId("5c8bc15780f10143d8431e21"), "StudentName" : "Chris" } { "_id" ...
Read MoreHow to find if a column is auto_increment in MySQL?
To find if a column is auto_increment in MySQL, you can use the following syntax −select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='yourDatabaseName' and TABLE_NAME='yourTableName' and EXTRA like '%auto_increment%';Let us first create a table. Here, ClientId is set AUTO_INCREMENT −mysql> create table autoIncrementTableDemo -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int, -> ClientAddress varchar(100), -> ClientCountryName varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)Now, let us find whether any of the column is auto_increment −mysql> select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='test' and TABLE_NAME='autoIncrementTableDemo' and EXTRA ...
Read MoreResolve ‘multi update only works with $ operators’ in MongoDb?
You can use $set operator for this. The syntax is as follows −db.yourCollectionName.update({ }, {'$set': "yourFieldName": "yourValue" }, false, true);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.unconditionalUpdatesDemo.insertOne({"ClientName":"Larry", "ClientAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c8eb7372f684a30fbdfd557") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Mike", "ClientAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c8eb73f2f684a30fbdfd558") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Sam", "ClientAge":27}); { "acknowledged" : true, "insertedId" : ObjectId("5c8eb7462f684a30fbdfd559") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Carol", "ClientAge":29}); { "acknowledged" : true, "insertedId" : ObjectId("5c8eb7502f684a30fbdfd55a") }Display all documents from a ...
Read MoreMySQL query to display all the fields that contain a capital letter?
To display all the fields that contain a capital letter, use the RLIKE that performs a pattern match of a string expression against a pattern.Let us first create a table −mysql> create table contains_capital_letterDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100) -> ); Query OK, 0 rows affected (1.42 sec)Following is the query to insert some records in the table using insert command −mysql> insert into contains_capital_letterDemo(Name) values('Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into contains_capital_letterDemo(Name) values('larry'); Query OK, 1 row affected (0.12 sec) mysql> ...
Read MoreHow to select distinct value from one MySQL column only?
To select distinct value from one column only, you can use aggregate function MAX() along with GROUP BY. Let us first create a table −mysql> create table distinctFromOneColumn -> ( -> StudentId int, -> StudentName varchar(100) -> ); Query OK, 0 rows affected (0.77 sec)Following is the query to insert records in the table using insert command −mysql> insert into distinctFromOneColumn values(1001, 'John'); Query OK, 1 row affected (0.15 sec) mysql> insert into distinctFromOneColumn values(1002, 'Carol'); Query OK, 1 row affected (0.15 sec) mysql> insert into distinctFromOneColumn values(1001, 'Sam'); Query OK, 1 row affected ...
Read MoreC++ Program to Implement Queue
QueueThe queue which is implemented as FIFO where insertions are done at one end (rear) and deletions are done from another end (front). The first element that entered is deleted first.Queue operations are −EnQueue (int data) − Insertion at rear endint DeQueue()− Deletion from front endThis is a C++ program to implement queue using array.AlgorithmBegin function Enqueue() to insert elements in queue: If queue is completely filled up then print “Overflow”. Otherwise insert element at rear. Update the value of rear End Begin function Dequeue() to delete elements from ...
Read MoreHow to compare timestamps in MySQL?
To compare timestamps in MySQL, you can use DATE(). Let us first create a table−mysql> create table comparingTimestampDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> AdmissionDate timestamp -> ); Query OK, 0 rows affected (0.54 sec)Following is the query to insert records in the table using insert command −mysql> insert into comparingTimestampDemo(AdmissionDate) values('2019-03-31'); Query OK, 1 row affected (0.13 sec) mysql> insert into comparingTimestampDemo(AdmissionDate) values('2019-04-10'); Query OK, 1 row affected (0.12 sec) mysql> insert into comparingTimestampDemo(AdmissionDate) values('2019-04-15'); Query OK, 1 row affected (0.17 sec) mysql> insert into comparingTimestampDemo(AdmissionDate) values('2019-03-29'); Query OK, 1 ...
Read MoreAdd10 minutes to MySQL datetime format?\\n\\n
Use DATE_ADD() to add 10 minutes to datetime format. Following is the syntax −select date_add(yourColumnName ,interval 10 minute) from yourTableName;Let us first create a table −mysql> create table add10MinuteDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> DelayDatetime datetime -> ); Query OK, 0 rows affected (0.83 sec)Following is the query to insert records in the table using insert command −mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-01-23 12:45:56'); Query OK, 1 row affected (0.16 sec) mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-03-25 10:30:23'); Query OK, 1 row affected (0.19 sec) mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-04-21 04:04:30'); Query ...
Read MoreHow to convert string to char array in C++?
This is a C++ program to convert string to char array in C++. This can be done in multiple different waysType1AlgorithmBegin Assign a string value to a char array variable m. Define and string variable str For i = 0 to sizeof(m) Copy character by character from m to str. Print character by character from str. EndExample#include #include using namespace std; int main() { char m[]="Tutorialspoint"; string str; int i; for(i=0;i
Read MoreHow are virtual functions implemented in C++?
Virtual functions in C++ used to create a list of base class pointers and call methods of any of the derived classes without even knowing kind of derived class object. Virtual functions are resolved late, at runtime.Here is an implementation of virtual function in C++ program −Example#include using namespace std; class B { public: virtual void s() { //virtual function cout
Read More