Found 6702 Articles for Database

Using MongoDB updateOne() & insertOne()

AmitDiwan
Updated on 30-Jun-2020 07:44:44

765 Views

MongoDB insertOne() inserts a document into a collection, whereas updateOne() update a single document in a collection based on a query filter.Let us create a collection with documents −> db.demo735.insertOne({id:1, Name:"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ead51b657bb72a10bcf0652") } > db.demo735.insertOne({id:1, Name:"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ead51bb57bb72a10bcf0653") } > db.demo735.insertOne({id:1, Name:"Bob"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ead51be57bb72a10bcf0654") } > db.demo735.insertOne({id:1, Name:"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ead51c757bb72a10bcf0655") }Display all documents from a collection with the help of find() method −> db.demo735.find();This will produce the following output −{ "_id" ... Read More

Difference between “now” and a given date with MongoDB?

AmitDiwan
Updated on 30-Jun-2020 07:42:37

1K+ Views

To get the difference between dates in MongpDB, use aggregate(). Let us create a collection with documents −> db.demo734.insertOne({GivenDate:new ISODate("2020-01-10")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ead4f1a57bb72a10bcf064e") } > db.demo734.insertOne({GivenDate:new ISODate("2020-02-20")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ead4f2157bb72a10bcf064f") } > db.demo734.insertOne({GivenDate:new ISODate("2010-12-01")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ead4f2b57bb72a10bcf0650") } > db.demo734.insertOne({GivenDate:new ISODate("2020-05-01")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ead506f57bb72a10bcf0651") }Display all documents from a collection with the help of find() method −> db.demo734.find();This will produce the following output −{ "_id" : ObjectId("5ead4f1a57bb72a10bcf064e"), "GivenDate" : ISODate("2020-01-10T00:00:00Z") } { "_id" : ObjectId("5ead4f2157bb72a10bcf064f"), "GivenDate" ... Read More

Difference between Simple and Complex View in SQL

Nitin Sharma
Updated on 09-Jun-2020 09:02:15

2K+ Views

Before discussing on Simple and complex, first we should know what is View. A View is the logical virtual table created from one or more tables which can be primarily used to fetch the columns from one or more different tables at a time. On the basis of tables involved in the view we can distinguish between Simple and Complex View in SQL.Following are the important differences between Simple and Complex View.Sr. No.KeySimple ViewComplex View1DefinitionSimple View in SQL is the view created by involving only single table. In other words we can say that there is only one base table ... Read More

Difference between Views and Materialized Views in SQL

Kiran Kumar Panigrahi
Updated on 02-Sep-2023 12:58:54

54K+ Views

The main constituent of any database is its tables, in order to make data accessibility custom there is concept of Views in other words we can say that with the help of Views of a table we can restrict any user to access only that data which is supposed to be accessed by him. Now on the basis of characteristic and features of the views we can distinguish between Views and Materialized Views. In this article, we will discuss the important differences between Views and Materialized Views in SQL. But before, let’s have look into the basics of views and ... Read More

Difference between Hive and HBase

Kiran Kumar Panigrahi
Updated on 28-Jul-2022 10:38:07

2K+ Views

Hive and HBase are Hadoop-based Big Data solutions. These technologies serve different purposes in almost any real use scenario. When you log onto Facebook, you may see your friend's list, a news feed, ad suggestions, friend suggestions, etc. Twitter is similar.Apache Hadoop, along with other technologies we'll explore today, such as Apache Hive vs. Apache HBase, is how Facebook loads all of its messy data in a presentable manner. Apache Hadoop enables Facebook's two billion-plus daily users.Because Big Data systems are complicated, all technologies must be used together. Hive is recommended for analyzing time-series data. It can evaluate trends and ... Read More

Count no. of characters and words in a string in PL/SQL

Sunidhi Bansal
Updated on 15-May-2020 10:21:54

2K+ Views

We are given a string of any length and the task is to calculate the count of characters and words in a string using PL/SQL.PL/SQL is a combination of SQL along with the procedural features of programming languages.It was developed by Oracle Corporation in the early 90's to enhance the capabilities of SQL. PL/SQL is one of three key programming languages embedded in the Oracle Database, along with SQL itself and Java.In PL/SQL block, we have DECLARE block which is used to declare the variables used in programming and we have BEGIN block where we write the logic for the ... Read More

How to move an array of embedded documents up to parent and change key/value with aggregation pipeline?

AmitDiwan
Updated on 15-May-2020 09:26:12

923 Views

Use $replaceRoot in MongoDB aggregation. The $replaceRoot replaces the input document with the specified document. The operation replaces all existing fields in the input document, including the _id field. Let us create a collection with documents −> db.demo733.insertOne( ...    { ...       "SubjectDetails": ...       [ ...          { ...             SubjectName:"MongoDB", ...             "Marks":85 ...          }, ...          { ...             SubjectName:"MySQL", ...             ... Read More

How to add a field with specific datatype (list, object) in an existing MongoDB document?

AmitDiwan
Updated on 15-May-2020 09:23:53

403 Views

You can use $set. Let us create a collection with documents −> db.demo732.insertOne({_id:1, Language:"English"}); { "acknowledged" : true, "insertedId" : 1 } > db.demo732.insertOne({_id:2, Language:"Hindi"}); { "acknowledged" : true, "insertedId" : 2 }Display all documents from a collection with the help of find() method −> db.demo732.find();This will produce the following output −{ "_id" : 1, "Language" : "English" } { "_id" : 2, "Language" : "Hindi" }Following is the query to add a field with specific datatype (list, object) in an existing MongoDB document −> db.demo732.update({_id:1}, ... { $set:{details:{'subjectName':"MongoDB"}, studentDetails:[{Name:"David"}, {CountryName:"US"}]}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : ... Read More

How to display a specific field in array using $project in MongoDB and ignore other fields?

AmitDiwan
Updated on 15-May-2020 09:22:15

742 Views

To display a specific field, use $project along with $unwind. To ignore a field, set to 0. Let us create a collection with documents −> db.demo731.insertOne({ "ProductInformation": [ { ProductId:"Product-1", ProductPrice:80 }, { ProductId:"Product-2", ProductPrice:45 }, { ProductId:"Product-3", ProductPrice:50 } ] } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5eac5efd56e85a39df5f6341") }Display all documents from a collection with the help of find() method −> db.demo731.find();This will produce the following output −{ "_id" : ObjectId("5eac5efd56e85a39df5f6341"), "ProductInformation" : [ { "ProductId" : "Product-1", "ProductPrice" : 80 }, { "ProductId" : "Product-2", "ProductPrice" : 45 }, { "ProductId" : "Product-3", "ProductPrice" : ... Read More

Match MongoDB documents with field value greater than a specific number and fetch them?

AmitDiwan
Updated on 15-May-2020 09:20:25

412 Views

To match, use $match in MongoDB. For values greater than a specific number, use $gt. Let us create a collection with documents −> db.demo730.insertOne({"Name" : "Chris", "Marks" : 33 }); {    "acknowledged" : true,    "insertedId" : ObjectId("5eac54cd56e85a39df5f6339") } > db.demo730.insertOne({ "Name" : "David", "Marks" : 89}); {    "acknowledged" : true,    "insertedId" : ObjectId("5eac54cd56e85a39df5f633a") } > db.demo730.insertOne({ "Name" : "Chris", "Marks" : 45 }); {    "acknowledged" : true,    "insertedId" : ObjectId("5eac54ce56e85a39df5f633b") }Display all documents from a collection with the help of find() method −> db.demo730.find();This will produce the following output −{ "_id" : ObjectId("5eac54cd56e85a39df5f6339"), "Name" ... Read More

Advertisements