Smita Kapse has Published 558 Articles

Get the average of marks in MongoDB with aggregate?

Smita Kapse

Smita Kapse

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

321 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

197 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

Is it possible to use MongoDB field value as pattern in $regex?

Smita Kapse

Smita Kapse

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

147 Views

Yes, for this, use $indexOfCP operator along with aggregate framework. Let us first create a collection with documents −> db.patterDemo.insertOne(    {       "ClientName": "John", "ClientWebsiteName":"webbuziness.com/John/business"    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea40acef71edecf6a1f68d") } > db.patterDemo.insertOne(    {       "ClientName": "Carol", ... Read More

Java DatabaseMetaData getMaxBinaryLiteralLength() method with example.

Smita Kapse

Smita Kapse

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

52 Views

The getMaxBinaryLiteralLength() method of the DatabaseMetaData interface is used to find out the maximum number of characters (hex) that the underlying database allows for a binary literal.This method returns an integer value, representing the maximum length of a binary literal. If this value is 0 it indicates that there is ... Read More

Does MySQL DROP TABLE completely remove the table or just the structure?

Smita Kapse

Smita Kapse

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

75 Views

The DROP TABLE removes the table completely and also removes all data. If you want to remove all data completely and wants the table structure, then you can use TRUNCATE TABLE command. The TRUNCATE command will recreate the table.Let us first check the DROP TABLE. For that, we will first ... Read More

Retrieving an embedded object as a document via the aggregation framework in MongoDB?

Smita Kapse

Smita Kapse

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

237 Views

To retrieve an embedded object as a document, use the aggregation $replaceRoot. Let us first create a collection with documents −> db.embeddedObjectDemo.insertOne(    { _id: new ObjectId(),       "UserDetails": { "UserName": "John", "UserAge": 24, "UserEmailId": "John22@gmail.com" }    } ); {    "acknowledged" : true,    "insertedId" : ... Read More

Extract particular element in MongoDB within a Nested Array?

Smita Kapse

Smita Kapse

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

480 Views

To extract the particular element in MongoDB, you can use $elemMatch operator. Let us first create a collection with documents −> db.particularElementDemo.insertOne(    {       "GroupId" :"Group-1",       "UserDetails" : [          {             "UserName" : "John",   ... Read More

Display first selected row in MySQL?

Smita Kapse

Smita Kapse

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

142 Views

You can use ORDER BY for this. Let us first create a table −mysql> create table DemoTable    (    Value int    ); Query OK, 0 rows affected (0.20 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.07 ... Read More

Display a value with $addToSet in MongoDB with no duplicate elements?

Smita Kapse

Smita Kapse

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

143 Views

Use $addToSet operator to ensures that there are no duplicate items added to the set. Let us first create a collection with documents −> db.getDistinctDemo.insertOne({"Values":[100, 200]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef69f9ef71edecf6a1f69d") } > db.getDistinctDemo.insertOne({"Values":[300, 100]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef6a07ef71edecf6a1f69e") }Display all ... Read More

Java DatabaseMetaData getMaxTableNameLength() method with example.

Smita Kapse

Smita Kapse

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

61 Views

The getMaxTableNameLength() method of the DatabaseMetaData interface is used to find out the maximum number of characters that the underlying database allows in the name of a tableThis method returns an integer value, representing the maximum number of characters allowed in a table name. If this value is 0 it ... Read More

Advertisements