Smita Kapse has Published 498 Articles

MongoDB query to find documents having two values in an array conforming to multiple criteria?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

333 Views

For this, use $elemMatch operator. Let us first create a collection with documents −> db.findDocumentsHaving2Demo.insertOne(    {_id : 101, Values: [78, 98]} ); { "acknowledged" : true, "insertedId" : 101 } > db.findDocumentsHaving2Demo.insertOne(    {_id :102, Values : [89, 102]} ); { "acknowledged" : true, "insertedId" : 102 }Following is ... Read More

Perform MongoDB array concatenation to concatenate records

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

144 Views

For array concatenation, use $concatArrays operator. Let us first create a collection with documents −>db.arrayConcatenationDemo.insertOne({"TeacherName":["Chris", "Robert"], "StudentName":["Mike", "Sam"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce921c078f00858fb12e911") }Following is the query to display all documents from a collection with the help of find() method −> db.arrayConcatenationDemo.find().pretty();This will produce the following ... Read More

MySQL system variable table_type doesn't work?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

98 Views

The variable table_type doesn’t work since this variable is deprecated as of MySQL 5.5.3. Use default_storage_engine instead. Following is the syntax −SET default_storage_engine = yourTableEngine;The table engine name may be InnoDB or MyISAM. Here, we will set engine type to MyISAM −mysql> SET default_storage_engine=MyISAM; Query OK,  0 rows affected (0.00 sec)Let us create a table.mysql> create ... Read More

Removing empty fields from MongoDB

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

482 Views

To remove empty fields, use deleteMany(). Let us first create a collection with documents −> db.removeEmptyFieldsDemo.insertOne({"StudentName":""}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce92b9578f00858fb12e919") } > db.removeEmptyFieldsDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce92b9878f00858fb12e91a") } > db.removeEmptyFieldsDemo.insertOne({"StudentName":""}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce92b9c78f00858fb12e91b") } ... Read More

How to use MySQL CASE statement while using UPDATE Query?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

862 Views

For using MySQL CASE statement while using UPDATE Query, you can use CASE statement. Let us first create a table −mysql> create table DemoTable    (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserScore int    ); Query OK, 0 rows affected (0.29 sec)Insert some records in the table ... Read More

Retrieving array values from a find query in MongoDB?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

137 Views

To retrieve array values, use dot(.) notation. Let us first create a collection with documents −> db.retrievingArrayDemo.insertOne(    { "UserDetails" : [       { "UserName" : "John",  "UserAge" : 23 } ],       "UserCountryName" : "AUS",       "UserLoginDate" : new ISODate(),       "UserMessage" : "Hello"    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce9718478f00858fb12e920") } > db.retrievingArrayDemo.insertOne(    { "UserDetails" : [       ... Read More

Get the sum of a column in all MySQL rows?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

218 Views

Use aggregate function SUM() to get the sum of a column in al rows. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Amount int    ); Query OK, 0 rows affected (0.20 sec)Insert some records in the table ... Read More

Hang Up Your iPhone with the Click of a Button

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

347 Views

When you’re on a call, you can hang up the phone by pressing the Side button on your iOS device. This button is also called as sleep/wake up or lock button.The devices and iOS are specifically designed the way that pressing the power button while on a call will immediately ... Read More

Get the average of marks in MongoDB with aggregate?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

487 Views

Use $avg operator along with aggregate framework. Let us first create a collection with documents. Here, one of the fields is StudentScore −> db.averageReturiningNullDemo.insertOne(    {"StudentDetails" : { "StudentScore" : 89 } }); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce9822e78f00858fb12e927") } > db.averageReturiningNullDemo.insertOne(    {"StudentDetails" : { "StudentScore" ... Read More

What is the MySQL alias shorthand?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

269 Views

You need to give name explicitly or you can remove AS command. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20)    ); Query OK, 0 rows affected (0.21 sec)Insert some records in the table using ... Read More

Advertisements