<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abhinav Pandey</title>
    <description>The latest articles on DEV Community by Abhinav Pandey (@abhinav_pandey).</description>
    <link>https://dev.to/abhinav_pandey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F827986%2Fac37618b-f47d-475c-a68b-db2d45216235.jpeg</url>
      <title>DEV Community: Abhinav Pandey</title>
      <link>https://dev.to/abhinav_pandey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhinav_pandey"/>
    <language>en</language>
    <item>
      <title>NO SQL - Mongodb 101</title>
      <dc:creator>Abhinav Pandey</dc:creator>
      <pubDate>Sat, 28 Jan 2023 12:44:07 +0000</pubDate>
      <link>https://dev.to/abhinav_pandey/no-sql-mongodb-101-47p9</link>
      <guid>https://dev.to/abhinav_pandey/no-sql-mongodb-101-47p9</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mB5dEqe_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5mzhjluqqhcgjb2b2zqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mB5dEqe_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5mzhjluqqhcgjb2b2zqn.png" alt="Image description" width="766" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For installation in Ubuntu 22:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://wiki.crowncloud.net/How_To_Install_Duf_On_Ubuntu_22_04?How_to_Install_Latest_MongoDB_on_Ubuntu_22_04"&gt;https://wiki.crowncloud.net/How_To_Install_Duf_On_Ubuntu_22_04?How_to_Install_Latest_MongoDB_on_Ubuntu_22_04&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CRUD Operations:&lt;br&gt;
&lt;a href="https://www.mongodb.com/docs/manual/crud/"&gt;https://www.mongodb.com/docs/manual/crud/&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    db.help()                    help on db methods
db.mycoll.help()             help on collection methods
sh.help()                    sharding helpers
rs.help()                    replica set helpers
help admin                   administrative help
help connect                 connecting to a db help
help keys                    key shortcuts
help misc                    misc things to know
help mr                      mapreduce

show dbs                     show database names
show collections             show collections in current database
show users                   show users in current database
show profile                 show most recent system.profile entries with time &amp;gt;= 1ms
show logs                    show the accessible logger names
show log [name]                                  prints out the last segment of log in memory, 'global' is default
use &amp;lt;db_name&amp;gt;                                    set current database
db.mycoll.find()                                     list objects in collection mycoll
db.mycoll.find( { a : 1 } )                      list objects in mycoll where a == 1
it                                                                   result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x               set default number of items to display on shell
exit                                                             quit the mongo shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Collections:&lt;br&gt;
A collection in MongoDB is a group of documents.&lt;br&gt;
Collections in a NoSQL database like MongoDB correspond to tables in relational database management systems (RDBMS) or SQL databases.  As such, collections don’t enforce a set schema, and documents within a single collection can have widely different fields.&lt;/p&gt;

&lt;p&gt;BASIC:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D049W5FF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gtsfq2dxvo4mc2iabhu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D049W5FF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gtsfq2dxvo4mc2iabhu.png" alt="Image description" width="880" height="844"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;mongo&lt;/li&gt;
&lt;li&gt;show dbs&lt;/li&gt;
&lt;li&gt;use showDB&lt;/li&gt;
&lt;li&gt;show collections&lt;/li&gt;
&lt;li&gt;db.products.find()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;VIEW:&lt;br&gt;
If users collection doesnt exist in the database, then it will create a new one.&lt;br&gt;
To view a collection in MongoDB, you can use the find() method on the collection. This method returns a cursor to the documents in the collection, which you can then iterate through to display the documents.&lt;/p&gt;

&lt;p&gt;For example, if you have a collection named "users" in a MongoDB database, you can view the documents in that collection using the following command in the MongoDB shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.find()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return all documents in the "users" collection. If you want to see specific documents, you can pass a query document to the find() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.find({"age": 25})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return all documents in the "users" collection where the "age" field is equal to 25.&lt;/p&gt;

&lt;p&gt;You can also use the cursor returned by find() to iterate through the documents, and get more options like limit, skip&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var cursor = db.users.find(); 
cursor.forEach(printjson);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will display the documents one at a time, using the printjson() function to pretty-print each document.&lt;/p&gt;

&lt;p&gt;UPDATE:&lt;br&gt;
To update a document in MongoDB, you can use the updateOne() or updateMany() method on the collection. The updateOne() method updates the first document that matches a specified filter, while the updateMany() method updates all documents that match a specified filter.&lt;/p&gt;

&lt;p&gt;For example, if you have a collection named "users" in a MongoDB database, you can update a document with the following command in the MongoDB shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.updateOne(    { "name" : "John Doe" },    { $set: { "age": 30 } } );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This updates the first document in the "users" collection where the "name" field is "John Doe" and sets the "age" field to 30.&lt;/p&gt;

&lt;p&gt;You can also use the updateMany() method to update multiple documents that match a specified filter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.updateMany(    { "age": 25 },    { $inc: { "age": 5 } } );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This updates all documents in the "users" collection where the "age" field is equal to 25 and increments the "age" field by 5.&lt;/p&gt;

&lt;p&gt;Signifiance of _id:&lt;br&gt;
In MongoDB, every document stored in a collection has a unique identifier called the _id. This field is automatically added by MongoDB if one is not specified when inserting the document. The _id serves as the primary key for the document and is used for indexing and sharding. It is also used to ensure that every document in a collection is unique and can be efficiently retrieved using this field. It can be any type of value, but is typically a 12-byte ObjectId or a string.&lt;/p&gt;

&lt;p&gt;can you have two  same _id field in two different documents in two different collections:&lt;br&gt;
In MongoDB, the _id field is a unique identifier that is automatically generated for each document when it is inserted into a collection. This means that the _id value is unique within a single collection.&lt;/p&gt;

&lt;p&gt;However, it is possible to have two documents with the same _id value in different collections. This is because the uniqueness constraint for the _id field only applies within a single collection and not across collections.&lt;/p&gt;

&lt;p&gt;For example, if you have two collections "users" and "employees" both can have a document with the same _id value, such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.insert({ _id: 1, name: "John Doe" }); 
db.employees.insert({ _id: 1, name: "Jane Doe" });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is possible because both documents are in different collections and MongoDB considers them as separate documents.&lt;/p&gt;

&lt;p&gt;It's important to note that while this is possible, it's not always a good practice. It can lead to confusion and make it harder to uniquely identify documents across different collections. It's generally recommended to use a different unique identifier or use a combination of fields as a unique identifier to maintain data integrity.&lt;/p&gt;

&lt;p&gt;REMOVE  a field:&lt;br&gt;
You can remove a field from a document using the $unset update operator. The $unset operator takes the field name as the key and sets its value to 1, indicating that the field should be removed.&lt;/p&gt;

&lt;p&gt;You can use the updateOne() or updateMany() method to remove a field from a document.&lt;br&gt;
Here is an example of how you can use the updateOne() method to remove a field "fieldName" from a document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.updateOne(    { _id: ObjectId("5f8a12d3c3c74a2e9c8b456b") },    { $unset: { fieldName: 1 } } )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for remove many documents you can use updateMany() method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.updateMany(    {},    { $unset: { fieldName: 1 } } )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will remove the field named "fieldName" from all the documents in the collection.&lt;/p&gt;

&lt;p&gt;INSERT:&lt;br&gt;
In MongoDB, you can insert a document into a collection using the insertOne() or insertMany() method.&lt;/p&gt;

&lt;p&gt;Here is an example of how you can use the insertOne() method to insert a document into a collection named "collection":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.insertOne({
    _id: ObjectId("5f8a12d3c3c74a2e9c8b456b"),
    fieldName: "value",
    fieldName2: "value2" 
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for insert many documents at once you can use insertMany() method :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.insertMany([
    { _id: ObjectId("5f8a12d3c3c74a2e9c8b456b"), fieldName: "value1" },
    { _id: ObjectId("5f8a12d3c3c74a2e9c8b456c"), fieldName: "value2" },
    { _id: ObjectId("5f8a12d3c3c74a2e9c8b456d"), fieldName: "value3" } 
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;REMOVE:&lt;/p&gt;

&lt;p&gt;To remove a document from a collection, you can use the deleteOne() or deleteMany() method.&lt;/p&gt;

&lt;p&gt;Here is an example of how you can use the deleteOne() method to remove a document with a specific _id from a collection named "collection":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.deleteOne({ _id: ObjectId("5f8a12d3c3c74a2e9c8b456b") });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for removing many documents you can use deleteMany() method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.deleteMany({ fieldName: "value" });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will remove all the documents where the field named "fieldName" has the value "value" from the collection.&lt;br&gt;
It's important to note that the deleteOne() method will remove only one matching document, while the deleteMany() method will remove all the matching documents. Also, if you don't pass any query to the delete methods, it will remove all the documents in the collection&lt;/p&gt;

&lt;p&gt;FIND queries:&lt;br&gt;
There are several different types of queries that can be added to the find() method in MongoDB to filter the results. Some examples include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Equality match: {field: value}
example: db.collection.find({age: 25})&lt;/li&gt;
&lt;li&gt;Comparison operators: {field: {$gt: value}}
example: db.collection.find({age: {$gt: 20}})&lt;/li&gt;
&lt;li&gt;Logical operators: {$or: [{field: value}, {field: value}]}
example: db.collection.find({$or: [{age: 25}, {name: "John"}]})&lt;/li&gt;
&lt;li&gt;Existence: {field: {$exists: true/false}}
example: db.collection.find({age: {$exists: true}})&lt;/li&gt;
&lt;li&gt;Regex: {field: {$regex: /pattern/}}
example: db.collection.find({name: {$regex: /^J/}})&lt;/li&gt;
&lt;li&gt;Combining multiple conditions: {field: value, field: value}
example: db.collection.find({age: {$gt: 25}, gender: "male"})&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are just a few examples of the types of queries that can be added to the find() method. MongoDB has many more options for querying data, including the use of projection, sorting, and limiting the number of results returned.&lt;/p&gt;

&lt;p&gt;Comparision operators:&lt;br&gt;
Comparison operators in MongoDB can be used to compare the values of fields in documents and filter the results of a query. Some common comparison operators include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;$eq: Matches values that are equal to a specified value.
example: db.collection.find({age: {$eq: 25}})&lt;/li&gt;
&lt;li&gt;$gt: Matches values that are greater than a specified value.
example: db.collection.find({age: {$gt: 25}})&lt;/li&gt;
&lt;li&gt;$gte: Matches values that are greater than or equal to a specified value.
example: db.collection.find({age: {$gte: 25}})&lt;/li&gt;
&lt;li&gt;$lt: Matches values that are less than a specified value.
example: db.collection.find({age: {$lt: 25}})&lt;/li&gt;
&lt;li&gt;$lte: Matches values that are less than or equal to a specified value.
example: db.collection.find({age: {$lte: 25}})&lt;/li&gt;
&lt;li&gt;$ne: Matches all values that are not equal to a specified value.
example: db.collection.find({age: {$ne: 25}})&lt;/li&gt;
&lt;li&gt;$in: Matches any of the values specified in an array.
example: db.collection.find({age: {$in: [25, 30, 35]}})&lt;/li&gt;
&lt;li&gt;$nin: Matches none of the values specified in an array.
example: db.collection.find({age: {$nin: [25, 30, 35]}})&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are just a few examples of the comparison operators that are available in MongoDB. You can use these operators in combination with other query operators to filter the results of a query more precisely.&lt;/p&gt;

&lt;p&gt;Logical operators:&lt;br&gt;
Logical operators in MongoDB can be used to combine multiple query conditions and filter the results of a query. Some common logical operators include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;$and: Matches all documents that match both of the specified query conditions.
example: db.collection.find({$and: [{age: {$gt: 25}}, {gender: "male"}]})&lt;/li&gt;
&lt;li&gt;$or: Matches all documents that match at least one of the specified query conditions.
example: db.collection.find({$or: [{age: {$lt: 25}}, {gender: "female"}]})&lt;/li&gt;
&lt;li&gt;$not: Matches all documents that do not match the specified query condition.
example: db.collection.find({age: {$not: {$gt: 25}}})&lt;/li&gt;
&lt;li&gt;$nor: Matches all documents that fail to match both of the specified query conditions.
example: db.collection.find({$nor: [{age: {$lt: 25}}, {gender: "female"}]})&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These logical operators can be used to filter the results of a query by combining multiple conditions. You can use these operators in combination with other query operators to filter the results of a query more precisely.&lt;/p&gt;

&lt;p&gt;Existence:&lt;br&gt;
The $exists operator in MongoDB can be used to check whether a field in a document exists or not. This operator can help you to filter out documents that have or don't have a certain field.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;$exists: true: Matches documents that contain the specified field.
example: db.collection.find({age: {$exists: true}})&lt;/li&gt;
&lt;li&gt;$exists: false: Matches documents that do not contain the specified field.
example: db.collection.find({age: {$exists: false}})&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example, you can use this operator to find all documents that have a field called "age" with a value of {$exists: true} and documents that don't have the "age" field with a value of {$exists: false}&lt;br&gt;
You can also use this operator in combination with other query operators to filter the results of a query more precisely.&lt;br&gt;
Note: It's also possible to check for the existence of fields inside sub-documents using dot notation.&lt;/p&gt;

&lt;p&gt;example: &lt;br&gt;
db.collection.find({"address.zipcode": {$exists: true}})&lt;/p&gt;

&lt;p&gt;It's also worth mentioning that, If you want to check for the existence of a field in an array, you can use the $elemMatch&lt;br&gt;
 operator.&lt;/p&gt;

&lt;p&gt;example: &lt;br&gt;
db.collection.find({hobbies: {$elemMatch: {$exists: true}}})&lt;/p&gt;

&lt;p&gt;REGEX:&lt;br&gt;
The $regex operator in MongoDB can be used to perform a regular expression search on string fields in a document. This operator allows you to filter documents based on a pattern or a set of patterns in a field's value.&lt;/p&gt;

&lt;p&gt;Here is an example of how you can use the $regex operator to find documents that have a field called "name" with a value that starts with "J":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.find({name: {$regex: /^J/}})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use the $options operator to specify options for the regular expression search. For example, you can use the "i" option to perform a case-insensitive search:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.find({name: {$regex: /^j/, $options: "i"}})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here are some more examples of the usage of $regex:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Matches any string that contains the word "example"
example: db.collection.find({name: {$regex: /example/}})&lt;/li&gt;
&lt;li&gt;Matches any string that starts with "J" and ends with "n"
example: db.collection.find({name: {$regex: /^J.*n$/}})&lt;/li&gt;
&lt;li&gt;Matches any string that contains a number
example: db.collection.find({name: {$regex: /\d/}})&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can use the $regex operator in combination with other query operators to filter the results of a query more precisely.&lt;/p&gt;

&lt;p&gt;Note: Be aware that Regular expressions can be computationally expensive, especially when querying large datasets or using complex regular expressions.&lt;/p&gt;

&lt;p&gt;Combining multiple conditions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.find({
     $and: [
         {age: {$gt: 25}},
         {$or: [
             {gender: "male"},
             {gender: "female"}
         ]}
     ]
 })        
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query will return all documents in the collection that have an "age" field greater than 25 and a "gender" field with the value of "male" or "female".&lt;/p&gt;

&lt;p&gt;You can combine multiple conditions to create a query that filters the results of a query as precisely as possible. It's also possible to use logical operator $not or $nor for negation.&lt;/p&gt;

&lt;p&gt;It's worth noting that, You have to be careful when using multiple conditions and logical operators, as it can affect the performance of your query if not used efficiently.&lt;/p&gt;

&lt;p&gt;BSON:&lt;br&gt;
JSON (JavaScript Object Notation) and BSON (Binary JSON) are both data formats that are used to represent and store data in a structured way. However, there are some key differences between the two:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Binary representation: BSON is a binary-encoded serialization of JSON-like documents. This means that BSON stores data in a binary format, whereas JSON stores data in a plain text format. This makes BSON more space-efficient and faster to parse, but it also means that BSON documents cannot be easily read or edited by humans.&lt;/li&gt;
&lt;li&gt;Data types: BSON supports a wider range of data types than JSON. For example, BSON includes support for binary data, timestamp, and 64-bit integers, whereas JSON only includes basic data types such as strings, numbers, and Booleans.&lt;/li&gt;
&lt;li&gt;Size: BSON documents are typically smaller in size than equivalent JSON documents due to its binary encoding.&lt;/li&gt;
&lt;li&gt;Use cases: JSON is primarily used for sending and receiving data over the internet, while BSON is primarily used for storing data in a MongoDB database. MongoDB uses BSON to represent documents within a collection and the BSON format is also used when storing data on disk or in memory.&lt;/li&gt;
&lt;li&gt;Compatibility: JSON is widely supported and can be easily used with many programming languages and platforms, whereas BSON is primarily used in the MongoDB ecosystem. BSON can be converted to and from JSON, so it can be easily integrated with other systems that use JSON.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In summary, JSON and BSON are both data formats that are used to represent and store data in a structured way. JSON is primarily used for sending and receiving data over the internet, while BSON is primarily used for storing data in MongoDB. BSON is more space-efficient and faster to parse, but it is not as human-readable as JSON.&lt;/p&gt;

&lt;p&gt;RELATIONSHIPS:&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Collection "users"
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9c"),
    "name": "John Smith",
    "email": "johnsmith@gmail.com"
}

//Collection "orders"
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9d"),
    "user": ObjectId("5f20d0a45f24a8c8e4ab2e9c"),  // this is the link
    "item": "Apple iPhone",
    "quantity": 2,
    "price": 800
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Collection "users"
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9c"),
    "name": "John Smith",
    "email": "johnsmith@gmail.com"
}

//Collection "posts"
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9d"),
    "user": ObjectId("5f20d0a45f24a8c8e4ab2e9c"),  // this is the link
    "title": "My first post",
    "content": "This is my first post on my blog."
},
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9e"),
    "user": ObjectId("5f20d0a45f24a8c8e4ab2e9c"),  // this is the link
    "title": "My second post",
    "content": "This is my second post on my blog."
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Collection "users"
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9c"),
    "name": "John Smith",
    "email": "johnsmith@gmail.com"
},
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9d"),
    "name": "Jane Doe",
    "email": "janedoe@gmail.com"
}

//Collection "posts"
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9e"),
    "title": "My first post",
    "content": "This is my first post on my blog.",
    "users": [
        ObjectId("5f20d0a45f24a8c8e4ab2e9c"),
        ObjectId("5f20d0a45f24a8c8e4ab2e9d")
    ]  // this is the link
},
{
    "_id": ObjectId("5f20d0a45f24a8c8e4ab2e9f"),
    "title": "My second post",
    "content": "This is my second post on my blog.",
    "users": [
        ObjectId("5f20d0a45f24a8c8e4ab2e9c")
    ]  // this is the link
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Filtered linkage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Find all the orders that belong to the user with _id = "5f20d0a45f24a8c8e4ab2e9c" and have a price greater than 100
var userId = ObjectId("5f20d0a45f24a8c8e4ab2e9c");
var orders = db.orders.find({ userId: userId, price: { $gt: 100 } });

// Extract the _id of each order
var orderIds = orders.map(function(order) { return order._id });

// Use the $filter operator to add the orders to the user document
db.users.updateOne(
    { _id: userId },
    { $push: { orders: { $each: [{ $filter: { input: orderIds, as: 'order', cond: { $gt: ['$$order.price', 100] } } }] } } }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>ExpressJS 101</title>
      <dc:creator>Abhinav Pandey</dc:creator>
      <pubDate>Sat, 28 Jan 2023 10:52:55 +0000</pubDate>
      <link>https://dev.to/abhinav_pandey/expressjs-101-4mk8</link>
      <guid>https://dev.to/abhinav_pandey/expressjs-101-4mk8</guid>
      <description>&lt;p&gt;npm init -y :&lt;br&gt;
creates a package.json file&lt;/p&gt;

&lt;p&gt;npm i --save-dev-nodemon:&lt;br&gt;
package which re-runs the server when any changes are saved&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "scripts": {
    "devStart": "nodemon server.js"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const app = express();
app.listen(3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the express package that has been installed will be called out as a function express()&lt;/p&gt;

&lt;p&gt;ERROR CODES:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get("/", (req, res) =&amp;gt; {
  console.log("HERE");
  //   res.send("HI");
  res.status(500).send("error from server 500");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The get() method takes two arguments: the first is the route or path, and the second is a callback function that is executed when a GET request is made to that route. The callback function typically takes two arguments: a request object and a response object, which are used to handle the incoming request and send a response back to the client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  res.json({
    a: "HI",
    image: {
      b: "hello",
    },
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To send files to be downloaded from the server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;res.download("server.js");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To render html component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  res.render("index");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this just gives an error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: No default engine was specified and no extension was provided.
    at new View (/home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/view.js:61:11)
    at Function.render (/home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/application.js:587:12)
    at ServerResponse.render (/home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/response.js:1039:7)
    at /home/abhinav-pandey/Github/LearnExpress/server.js:17:7
    at Layer.handle [as handle_request] (/home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/router/route.js:144:13)
    at Route.dispatch (/home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/router/route.js:114:3)
    at Layer.handle [as handle_request] (/home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/router/layer.js:95:5)
    at /home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/router/index.js:284:15
    at Function.process_params (/home/abhinav-pandey/Github/LearnExpress/node_modules/express/lib/router/index.js:346:12)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Solution:&lt;br&gt;
Setup view engine:&lt;br&gt;
pug OR ejs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.set("view engine", "ejs");
app.get("/", (req, res) =&amp;gt; {
  res.render("index");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;index.html should be named to index.ejs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;h1&amp;gt;2+2=&amp;lt;%= 2+2 %&amp;gt;&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it will run on the server and return back the value between the tag&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;res.render("index", { text: "page" });
&amp;lt;p&amp;gt;HELLO IM IN INDEX &amp;lt;%=text%&amp;gt;&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;res.render("index", { text123: "page" });
&amp;lt;p&amp;gt;HELLO IM IN INDEX &amp;lt;%=locals.text || 'PAGES'%&amp;gt;&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;locals is always going to passed from the viewengine.&lt;br&gt;
so even if text prop is not passed we can use an alternative.&lt;/p&gt;

&lt;p&gt;Custom routes in express:&lt;/p&gt;

&lt;p&gt;We can create custom files like routes/users.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const router = express.Router();
router.get("/", (req, res) =&amp;gt; {
  res.send("Users List");
});
router.get("/new", (req, res) =&amp;gt; {
  res.send("New User Form");
});
module.exports = router;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connect so that all the routes in the file will be a child of the parent route like /users&lt;/p&gt;

&lt;p&gt;so it will be&lt;br&gt;
/users/ &lt;br&gt;
/users/new&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userRouter = require("./routes/users");
app.use("/users", userRouter);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.route():&lt;br&gt;
Instead of doing this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.get("/:id", (req, res) =&amp;gt; {
  // req.params.id;
  res.send(`Get User with ID ${req.params.id}`);
});
router.put("/:id", (req, res) =&amp;gt; {
  // req.params.id;
  res.send(`Get User with ID ${req.params.id}`);
});
router.delete("/:id", (req, res) =&amp;gt; {
  // req.params.id;
  res.send(`Get User with ID ${req.params.id}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can :&lt;br&gt;
BETTER&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router
  .route("/:id")
  .get((req, res) =&amp;gt; {
    res.send(`Get User with ID ${req.params.id}`);
  })
  .put((req, res) =&amp;gt; {
    res.send(`Get User with ID ${req.params.id}`);
  })
  .delete((req, res) =&amp;gt; {
    res.send(`Get User with ID ${req.params.id}`);
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MIDDLEWARE:&lt;/p&gt;

&lt;p&gt;Middleware in Express is a function that runs between the request and the response in the processing of an HTTP request. Middleware functions can perform various tasks such as logging, authentication, validation, and more. Express uses a series of middleware functions that are executed in the order that they are defined. Each middleware function can perform some logic, and then pass control to the next middleware function using the next() function. Middleware functions can also end the request/response cycle by sending a response to the client or redirecting to another route.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function logger(req, res, next) {
  console.log(req.originalUrl);
  next();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(logger);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have to use this above the get request functions if we want to run this on those urls /.&lt;/p&gt;

&lt;p&gt;We can also run middleware to just a particular url like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get("/", logger, (req, res) =&amp;gt; {
  res.render("index", { text123: "page" });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.param():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.param("id", (req, res, next, id) =&amp;gt; {
  console.log(id);
  next();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if we dont use next() it will keep running forever.&lt;br&gt;
.param() is running before request and response so if there is no next it wont be able to further proceed&lt;/p&gt;

&lt;p&gt;Running static files from public:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(express.static("public"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of putting a get request of ./ we can use this to create a path to connect the index file or even render other files through that same request.&lt;/p&gt;

&lt;p&gt;We can navigate to &lt;a href="http://localhost:3000/test/tt.html" rel="noopener noreferrer"&gt;http://localhost:3000/test/tt.html&lt;/a&gt;&lt;br&gt;
to render this as well.&lt;/p&gt;

&lt;p&gt;express.urlencoded({extended: true}):&lt;br&gt;
Suppose we have a new.ejs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;form action="/users" method="POST"&amp;gt;
      &amp;lt;input type="text" name="fname" /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default express doesnt allow us to access the body we need to use another middleware for that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(express.urlencoded({ extended: true }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.get("/new", (req, res) =&amp;gt; {
  res.render("./users/new");
});

router.post("/", (req, res) =&amp;gt; {
  console.log(req.body.fname);
  res.send("Create User");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;req.body is coming from the form&lt;br&gt;
it is an object whose parameters are the name properties of the input fileds inside that form.&lt;/p&gt;

&lt;p&gt;res.redirect():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const users = [{ name: "Abhinav" }, { name: "Juan" }];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.post("/", (req, res) =&amp;gt; {
  const isValid = true;
  if (isValid) {
    users.push({ name: req.body.fname });
    res.redirect(`users/${users.length - 1}`);
  } else {
    console.log("ERROR");
    res.redirect("users/new");
  }
  console.log(req.body);
  res.send("Create User");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also get the query parameters directly coming to request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(req.query.name);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="http://localhost:3000/users?name=Kyle" rel="noopener noreferrer"&gt;http://localhost:3000/users?name=Kyle&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How to send json file to a get request from express:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get("/a", async (req, res) =&amp;gt; {
  try {
    const data = await fs.promises.readFile(
      "./public/assets/users.json",
      "utf8"
    );
    res.json(JSON.parse(data));
  } catch (err) {
    console.log(err);
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;fs in JS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require("fs");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CORS ERROR IN EXPRESS:&lt;br&gt;
allows any origin to post into the express server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cors = require("cors");
app.use(function (req, res, next) {
  res.header("Access-Control-Allow-Headers", "content-type");
  next();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(IMPORTANT)&lt;br&gt;
BODY-PARSER:&lt;br&gt;
the response body will come empty if we don't use this.&lt;br&gt;
we need to add a middleware for parsing the request body that is not being used. To fix this, you need to add a middleware function, such as "body-parser", to parse the request body and make it available on the req. body object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bodyParser = require("body-parser");
app.use(bodyParser.json());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>discuss</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Flutter based UI task</title>
      <dc:creator>Abhinav Pandey</dc:creator>
      <pubDate>Thu, 09 Jun 2022 16:03:00 +0000</pubDate>
      <link>https://dev.to/abhinav_pandey/flutter-based-ui-task-2nj6</link>
      <guid>https://dev.to/abhinav_pandey/flutter-based-ui-task-2nj6</guid>
      <description>&lt;p&gt;This task was very fun to do. I started by learning the basics and was doing the coding by myself. Then i used the introduction screen package. It was really helpful and i completed the app as suggested in the task. The materials used were as follows:&lt;/p&gt;

&lt;p&gt;References: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://flutter.dev/docs/get-started/install"&gt;Flutter Installation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://flutter.dev/docs"&gt;Flutter Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://flutter.dev/docs/cookbook/design/tabs"&gt;Tabs in Flutter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pub.dev/packages/dots_indicator"&gt;Making the dot animated when changing tabs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pub.dev/packages/introduction_screen"&gt;Introduction Screen Flutter Package&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Resourses:&lt;br&gt;
-Images:&lt;br&gt;
.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jullae9S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yk1axs2lfor753sod96u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jullae9S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yk1axs2lfor753sod96u.png" alt="page1.png" width="350" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ncVkNMJz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1gg5ypnaefc6us1vl7ox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ncVkNMJz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1gg5ypnaefc6us1vl7ox.png" alt="page2.png" width="351" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YP2guBqA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w92ctxhhfrhxkfx271rs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YP2guBqA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w92ctxhhfrhxkfx271rs.png" alt="page3.png" width="351" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F8JQ8KP7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vi46x1kdcmh43odf3o2s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F8JQ8KP7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vi46x1kdcmh43odf3o2s.png" alt="page4.png" width="552" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RP9PT9zm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cupfr50yvlae1qu5mvdm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RP9PT9zm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cupfr50yvlae1qu5mvdm.png" alt="Image description" width="331" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Dual boot Ubuntu and Windows 11💻</title>
      <dc:creator>Abhinav Pandey</dc:creator>
      <pubDate>Wed, 09 Mar 2022 15:13:34 +0000</pubDate>
      <link>https://dev.to/abhinav_pandey/dual-boot-ubuntu-and-windows-11-ij4</link>
      <guid>https://dev.to/abhinav_pandey/dual-boot-ubuntu-and-windows-11-ij4</guid>
      <description>&lt;p&gt;Why miss out features of windows by just using linux. We can simply dual boot them in the same pc with any memory loss. There are many steps to do carefully but its easy. If you have a single ssd we'll have to divide it into partitions, then install ubuntu in the new partition. But one can face many problems in the doing this. Lets get into the proper method and problem handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SSD PARTITION&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Firstly, we need to separate a partition of our ssd for linux. If you have a single ssd you can divide it using &lt;a href="https://docs.microsoft.com/en-us/windows-server/storage/disk-management/overview-of-disk-management#:~:text=Disk%20Management%20is%20a%20system,see%20Extend%20a%20basic%20volume." rel="noopener noreferrer"&gt;Disk Mangement&lt;/a&gt;. &lt;br&gt;
In Disk Management, follow the steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select the main drive(C:)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right click it and then shrink volume&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose the space you want for the new partion(100GB is enough)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the partion is created, right click it and set it up as new drive&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now your partion of 100GB is created the next step is to install Ubuntu in it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Preparing Ubuntu&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to download ubuntu LTS 20.4 from their website &lt;a href="https://ubuntu.com/" rel="noopener noreferrer"&gt;&lt;/a&gt;. Next you need a usb drive of minimum 8GB and download &lt;a href="https://rufus.ie/en/" rel="noopener noreferrer"&gt;Rufus&lt;/a&gt;. Then follow the exact steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Install Rufus and open it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the usb and the iso file you downloaded&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F95y320lbmbv2p2fse6mj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F95y320lbmbv2p2fse6mj.png" alt="Rufus"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select GPT in partion scheme NOT MBR&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then start it &lt;br&gt;
Now the preparation is done lets install it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;INSTALLATION&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Insert the usb in your pc and then restart. After it restarts and you see the logo keep pressing F12 Key and open BIOS menu.&lt;/p&gt;

&lt;p&gt;Then enter bios setup and disable secure boot. Again come in BIOS menu and boot the usb drive. Ubuntu logo will come up and a list will come up. Click the first one named ubuntu. Don't worry if you didn't choose any ubuntu will be come by default. Now you should be able to see ubuntu UI. Then follow the exact steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Donot install directly, first check if your sound, wifi connection and everything else is working&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then you can install ubuntu&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose the language and then when you get to the Update and other software panel, tick Normal Installation and Install third-party software&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you get to Installation type panel, click on SOMETHING ELSE, that way you won't lose any other data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The next step is very crucial, we need to manipulate the 100GB space and divide it. For this follow the exact steps in this video &lt;a href="https://youtu.be/5mfYj6uE1z0" rel="noopener noreferrer"&gt;VIDEO 1&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You might have created the swap area and Ext4 then set up the location username and password&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After this ubuntu should be installed properly in your partition.&lt;br&gt;
But many problems can be faced during the process and the process itself might not be same for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Handling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ERROR IN SSD PARTITION:&lt;/strong&gt;&lt;br&gt;
When you try to shrink volume of your main drive it might not show more space available although there enough free space.&lt;br&gt;
These can be caused by many files like pagfiles, hibernatefiles, swapfiles, program data and antivirus as well.&lt;br&gt;
Follow these steps carefully in the video if you face these problems.&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=X-0R7Q_vhmw&amp;amp;t=310s" rel="noopener noreferrer"&gt;VIDEO 2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TURN OFF INTEL RST:&lt;/strong&gt;&lt;br&gt;
If you get a message to turn off RAID/Intel RST during ubuntu installation then you have to follow a trick.&lt;br&gt;
Follow this &lt;a href="https://www.youtube.com/watch?v=wDrCaAdGuMk" rel="noopener noreferrer"&gt;VIDEO 3&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope you can successfully dual boot ubuntu and windows. If there were any difficulties or confusion, you can contact me directly.&lt;br&gt;
Also, thankyou so much for reading the whole blog. Hope i take more and give more from this community.&lt;br&gt;
Enjoy!&lt;/p&gt;

&lt;p&gt;Refrences:&lt;br&gt;
&lt;a href="https://youtu.be/5mfYj6uE1z0" rel="noopener noreferrer"&gt;Refrence 1&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=wDrCaAdGuMk" rel="noopener noreferrer"&gt;Refrence 1&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ubuntu</category>
    </item>
  </channel>
</rss>
