Found 6702 Articles for Database

How to know which storage engine is used in MongoDB?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

243 Views

To know which storage engine is used in MongoDB, you can use storageEngine. The syntax is as follows −db.serverStatus().storageEngine;To know all the configuration details of storage engine, you can use the following syntax:db.serverStatus().yourStorageEngineName;Let us implement the above syntax to know which storage engine is being used in MongoDB. The query is as follows −> db.serverStatus().storageEngine;The following is the output −{    "name" : "wiredTiger",    "supportsCommittedReads" : true,    "supportsSnapshotReadConcern" : true,    "readOnly" : false,    "persistent" : true }In order to know all configuration details about the above storage engine, the query is as follows −> db.serverStatus().wiredTiger;The following ... Read More

Adding/ concatenating text values within a MySQL SELECT clause?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

1K+ Views

To add/ concatenate text values within a select clause, you can use concat() function.Let us create a tablemysql> create table ConcatenatingDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserCountryName varchar(20) -> ); Query OK, 0 rows affected (0.82 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ConcatenatingDemo(UserName, UserCountryName) values('John', 'US'); Query OK, 1 row affected (0.14 sec) mysql> insert into ConcatenatingDemo(UserName, UserCountryName) values('Carol', 'UK'); Query OK, ... Read More

How to get distinct list of sub-document field values in MongoDB?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

248 Views

To get distinct list of sub-document field values, you can use dot(.). The syntax is as follows −db.yourCollectionName.distinct("yourOuterFieldName.yourInnerFieldName");To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.getDistinctListOfSubDocumentFieldDemo.insertOne(    ... {       ... "StudentId": 101,       ... "StudentPersonalDetails": [          ... {             ... "StudentName": "John",             ... "StudentAge":24          ... },          ... {             ... ... Read More

MySQL select count by value?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

90 Views

You can use COUNT() function for this. Let us first create a demo tablemysql> create table countValueDemo -> ( -> ShippingDatetime datetime, -> FirstValue int, -> SecondValue int -> ); Query OK, 0 rows affected (1.35 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into countValueDemo values('2019-01-23', 1, 2); Query OK, 1 row affected (0.24 sec) mysql> insert into countValueDemo values('2017-02-21', NULL, 2); Query OK, 1 row affected (0.13 sec) mysql> insert into countValueDemo values('2016-04-12', 1, NULL); ... Read More

How to fasten MySQL inserts?

George John
Updated on 30-Jul-2019 22:30:25

90 Views

You can speed the MySQL insert when you are inserting multiple records at the same time with the help of the following syntaxSTART TRANSACTION insert into insertDemo(yourColumnName1, yourColumnName2, ...N) values(yourValue1, yourValue2, ....N), (yourValue1, yourValue2, ....N), .......N commitLet us first create a demo tablemysql> create table insertDemo    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20),    -> StudentAge int    -> ); Query OK, 0 rows affected (0.72 sec)Insert multiple records at the same time. The query is as follows −mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec) mysql> insert into ... Read More

Exclude certain columns from SHOW COLUMNS in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

233 Views

Let us first create a demo tablemysql> create table excludeCertainColumnsDemo    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100),    -> StudentAge int,    -> StudentMarks int,    -> StudentAddress varchar(200)    -> ); Query OK, 0 rows affected (0.50 sec)Now you can check the description of table with the help of desc command. The query is as follows −mysql> desc excludeCertainColumnsDemo;The following is the output+----------------+--------------+------+-----+---------+----------------+ | Field          | Type         | Null | Key | Default | Extra          | +----------------+--------------+------+-----+---------+----------------+ | ... Read More

Perform aggregation sort in MongoDB?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

191 Views

You can use aggregate() method along with $sort() operator for this. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.aggregationSortDemo.insertOne({"StudentId":98, "StudentFirstName":"John", "StudentLastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90140c5705caea966c5587") } > db.aggregationSortDemo.insertOne({"StudentId":128, "StudentFirstName":"Carol", "StudentLastName":"Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90141b5705caea966c5588") } > db.aggregationSortDemo.insertOne({"StudentId":110, "StudentFirstName":"David", "StudentLastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90142f5705caea966c5589") } > db.aggregationSortDemo.insertOne({"StudentId":139, "StudentFirstName":"Chris", "StudentLastName":"Brown"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90146a5705caea966c558a") } > db.aggregationSortDemo.insertOne({"StudentId":125, "StudentFirstName":"Sam", "StudentLastName":"Williams"}); {    "acknowledged" : true, ... Read More

Convert MySQL Unix-Timestamp format to date format?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

527 Views

To achieve this, the following is the syntaxselect date_format(from_unixtime(yourColumnName), '%b %d, %Y %l:%i %p PDT') from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table unixTimeStampFormatDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> MyTimeStampValue bigint    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into unixTimeStampFormatDemo(MyTimeStampValue) values(1334428200); Query OK, 1 row affected (0.20 sec) mysql> insert into unixTimeStampFormatDemo(MyTimeStampValue) values(1513881000); Query OK, 1 row affected (0.15 ... Read More

Select MongoDB documents where a field either does not exist, is null, or is false?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

333 Views

You can use $in operator for this. Let us first create a collection with a document. The query to create a collection with a document is as follows −> db.selectMongoDBDocumentsWithSomeCondition.insertOne({"StudentId":1, "StudentName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9010215705caea966c557f") } > db.selectMongoDBDocumentsWithSomeCondition.insertOne({"StudentId":2, "StudentName":"Mike", "hasAgeGreaterThanOrEqualTo18":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90106a5705caea966c5580") } > db.selectMongoDBDocumentsWithSomeCondition.insertOne({"StudentId":3, "StudentName":"Carol", "hasAgeGreaterThanOrEqualTo18":false}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9010795705caea966c5581") } > db.selectMongoDBDocumentsWithSomeCondition.insertOne({"StudentId":4, "StudentName":"Sam", "hasAgeGreaterThanOrEqualTo18":null}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9010865705caea966c5582") } > db.selectMongoDBDocumentsWithSomeCondition.insertOne({"StudentId":5, "StudentName":"David", "hasAgeGreaterThanOrEqualTo18":false}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9010945705caea966c5583") } > db.selectMongoDBDocumentsWithSomeCondition.insertOne({"StudentId":6, "StudentName":"Chris", ... Read More

MongoDB print JSON without whitespace i.e. unpretty JSON?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

568 Views

To print unpretty json, use the following syntax −var yourVariableName= db.yourCollectionName.find().sort({_id:-1}).limit(10000); while( yourVariableName.hasNext() ) {    printjsononeline(yourVariableName.next() ); };To understand the syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.unprettyJsonDemo.insertOne({"StudentName":"John", "StudentAge":21, "StudentTechnicalSkills":["C", "C++"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c900df25705caea966c557d") } > db.unprettyJsonDemo.insertOne({"StudentName":"Carol", "StudentAge":22, "StudentTechnicalSkills":["MongoDB", "MySQL"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c900e085705caea966c557e") }all documents from a collection with the help of find() method. The query is as follows −> db.unprettyJsonDemo.find().pretty();The following is the output −{    "_id" : ObjectId("5c900df25705caea966c557d"),   ... Read More

Advertisements