Found 6702 Articles for Database

MySQL DateTime Now()+5 days/hours/minutes/seconds?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

457 Views

To update the current date and time to 5 days, you need to use the Now() + 5. That would update the entire date-time i.e. days, hour, minutes and seconds. To understand this, let us create a table. The query to create a table is as follows −mysql> create table UserInformationExpire    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(10),    -> UserInformationExpireDateTime datetime not null    -> ); Query OK, 0 rows affected (0.83 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> ... Read More

What are the different quote marks of MySQL?

Samual Sam
Updated on 30-Jul-2019 22:30:25

222 Views

You can use backticks and single quotes in MySQL. The backtick can be used around the column name and table name while single quotes can be used for the column name values.Let us take an example for both the quote marks. To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table QuotesDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(20),    -> UserAge int    -> ); Query OK, 0 rows affected (2.53 sec)Insert some records in the table using ... Read More

Get the date/time of the last change to a MySQL database?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

968 Views

You can get the date/time of the last change to a MySQL database with the help of INFORMATION_SCHEMA.TABLES. The syntax is as follows −SELECT update_time FROM information_schema.tables WHERE table_schema = 'yourDatabaseName’' AND table_name = 'yourTableName’;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table TblUpdate    -> (    -> Id int not null auto_increment primary key,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into TblUpdate(Name) ... Read More

Get the strings in the table records that ends with numbers?

Samual Sam
Updated on 30-Jul-2019 22:30:25

40 Views

You need to use REGEXP for this. The syntax is as follows −select *from yourTableName where yourColumnName REGEXP '[[:digit:]]$';To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table StringEndsWithNumber    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserId varchar(20),    -> UserName varchar(20)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into StringEndsWithNumber(UserId, UserName) values('123User', 'John'); Query OK, 1 row affected (0.18 sec) mysql> insert ... Read More

MongoDB Regex Search on Integer Value?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

1K+ Views

To perform Regex search on integer value, you need to use $where operator. The syntax is as follows:db.yourCollectionName.find({ $where: "/^yourIntegerPatternValue.*/.test(this.yourFieldName)" });To understand the above concept, let us create a collection with document. The query to create a collection with document is as follows:> db.regExpOnIntegerDemo.insertOne({"StudentId":2341234}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c70370c75eb1743ddddce21") } > db.regExpOnIntegerDemo.insertOne({"StudentId":123234}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c70371175eb1743ddddce22") } > db.regExpOnIntegerDemo.insertOne({"StudentId":9871234}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c70371875eb1743ddddce23") } > db.regExpOnIntegerDemo.insertOne({"StudentId":2345612}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c70372275eb1743ddddce24") } > db.regExpOnIntegerDemo.insertOne({"StudentId":1239812345}); {    "acknowledged" : true,    "insertedId" : ... Read More

How to sort inner array in MongoDB?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

3K+ Views

You can achieve this with the help of aggregate framework in MongoDB. To understand it, let us create a collection with document. The query to create a collection with document is as follows:> db.sortInnerArrayDemo.insertOne( ... ...    { ...       "EmployeeDetails": ...       { ...          "EmployeeAddress": ...          { ...             "EmployeeCountry": ...             [ ...                { ...                   "EmployeeZipCode":1003, ...       ... Read More

Querying internal array size in MongoDB?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

160 Views

You can use the $size operator for internal array size in MongoDB. The syntax is as follows:db.internalArraySizeDemo.aggregate(    [       {          $group: {             _id:yourObjectIdValue,             anyFieldName: {$first: {$size: "$yourArrayName" }}          }       }    ] );To understand the above syntax, let us create a collection with some documents. The query to create a collection with documents are as follows:>db.internalArraySizeDemo.insertOne({"EmployeeName":"Mike", "EmployeeTechnology":["Jav a Web Development", "Python Web Development"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6eff586fd07954a48906b2") } > ... Read More

Add new field to every document in a MongoDB collection?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

2K+ Views

To add new field to every document in a MongoDB collection, you can use $set operator. The syntax is as follows:db.yourCollectionName.update({}, { $set: {"yourFieldName": yourValue} }, false, true);To understand the above syntax, let us create a collection with some documents. The query to create a collection with documents is as follows:>db.addNewFieldToEveryDocument.insertOne({"StudentName":"John", "StudentAddress":"US "}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6efc0b6fd07954a48906ae") } >db.addNewFieldToEveryDocument.insertOne({"StudentName":"David", "StudentAddress":"U K"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6efc0b6fd07954a48906af") } >db.addNewFieldToEveryDocument.insertOne({"StudentName":"Carol", "StudentAddress":"U K"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6efc0b6fd07954a48906b0") } >db.addNewFieldToEveryDocument.insertOne({"StudentName":"Bob", "StudentAddress":"US" }); {    "acknowledged" : true,    "insertedId" : ... Read More

How to remove a field completely from a MongoDB document?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

805 Views

You can use $unset operator to remove a field completely from a MongoDb document. The syntax is as follows:db.yourCollectionName.update({}, {$unset: {yourFieldName:1}}, false, true);To understand the above syntax, let us create a collection with some documents. The query to create a collection with documents are as follows:> db.removeFieldCompletlyDemo.insertOne({"StudentName":"Larry", "StudentFavouriteSubject": ["Java", "C", "C++", "Python"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ef55a6fd07954a48906a3") } > db.removeFieldCompletlyDemo.insertOne({"StudentName":"Mike", "StudentFavouriteSubject": ["Javascript", "HTML5", "CSS3"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ef57b6fd07954a48906a4") } > db.removeFieldCompletlyDemo.insertOne({"StudentName":"Sam", "StudentFavouriteSubject": ["MongoDB", "MySQL", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ef59c6fd07954a48906a5") }Display all documents from a collection ... Read More

Converting string to date in MongoDB?

Nancy Den
Updated on 30-Jul-2019 22:30:25

886 Views

To convert the string to date in MongoDB, use the following syntax:db.yourCollectionName.aggregate(    [       {          $project:          {             anyVariableName:             {                $dateFromString:                {                   dateString: '$yourFieldName’                }             }          }       }    ] );To understand the above syntax, ... Read More

Advertisements