Smita Kapse has Published 498 Articles

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

Smita Kapse

Smita Kapse

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

190 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

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

Smita Kapse

Smita Kapse

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

122 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

308 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

625 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

225 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

205 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

Sort a MySQL table column value by part of its value?

Smita Kapse

Smita Kapse

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

174 Views

You can use ORDER BY RIGHT() for this. Let us first create a table −mysql> create table DemoTable    (    UserId varchar(100)    ); Query OK, 0 rows affected (0.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('User1234'); Query OK, 1 row affected ... Read More

How to query MongoDB a value with $lte and $in?

Smita Kapse

Smita Kapse

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

194 Views

Let us first create a collection with documents −> db.queryMongoValueDemo.insertOne(    {       _id:101,       "ScoreDetails":[{Score:80}, {Score:45}, {Score:25}, {Score:70}]    } ); { "acknowledged" : true, "insertedId" : 101 } > db.queryMongoValueDemo.insertOne(    {       _id:102,       "ScoreDetails":[{Score:80}, {Score:24}, {Score:34}]    } ... Read More

Java DatabaseMetaData getMaxColumnsInGroupBy() method with example.

Smita Kapse

Smita Kapse

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

67 Views

The getMaxColumnsInGroupBy() method of the DatabaseMetaData interface is used to find out the maximum number of columns that the underlying database allows in a GROUP BY clause.This method returns an integer value, representing the maximum number of columns allowed in a GROUP BY clause. If this value is 0 it ... Read More

How to display data from a MySQL column separated by comma?

Smita Kapse

Smita Kapse

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

757 Views

You can use GROUP_CONCAT() function from MySQL to display result as a comma separated list. Let us first create a table −mysql> create table DemoTable    (    Value int    ); Query OK, 0 rows affected (0.26 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Advertisements