<?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: Md.Tarikul</title>
    <description>The latest articles on DEV Community by Md.Tarikul (@tarikul01).</description>
    <link>https://dev.to/tarikul01</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%2F736871%2F949ad20c-b292-44d5-bbdd-e85e18203b81.jpeg</url>
      <title>DEV Community: Md.Tarikul</title>
      <link>https://dev.to/tarikul01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tarikul01"/>
    <language>en</language>
    <item>
      <title>Passwordless SSH Login to VPS Server Using Windows</title>
      <dc:creator>Md.Tarikul</dc:creator>
      <pubDate>Sat, 24 Aug 2024 10:42:24 +0000</pubDate>
      <link>https://dev.to/tarikul01/passwordless-ssh-login-to-vps-server-using-windows-15i8</link>
      <guid>https://dev.to/tarikul01/passwordless-ssh-login-to-vps-server-using-windows-15i8</guid>
      <description>&lt;h4&gt;
  
  
  &lt;strong&gt;This guide will walk you through the steps to set up passwordless SSH login to your VPS server from a Windows machine.&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftikty7rfkghxxjcrlk8q.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftikty7rfkghxxjcrlk8q.jpeg" alt="Image description" width="303" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;1. Generate SSH Key on Your Local Machine&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Start by creating an SSH key on your local Windows machine. This key will be used to authenticate your login to the VPS server without needing a password.&lt;br&gt;
bash&lt;br&gt;
&lt;code&gt;ssh-keygen -t rsa -b 4096 -C "your_email@example.com"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Explanation:&lt;/em&gt;&lt;br&gt;
-t rsa: Specifies the type of key to create, RSA in this case.&lt;br&gt;
-b 4096: The key size in bits (4096 is a strong key size).&lt;br&gt;
-C "&lt;a href="mailto:your_email@example.com"&gt;your_email@example.com&lt;/a&gt;": Adds a comment to the key, usually your &lt;em&gt;email.&lt;/em&gt;&lt;br&gt;
Output: This command generates two files:&lt;br&gt;
id_rsa: Your private key (keep this secure and do not share it).&lt;br&gt;
id_rsa.pub: Your public key (this will be copied to the VPS server).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Verify SSH Key Creation&lt;/strong&gt;&lt;br&gt;
Check if your SSH key has been created successfully by navigating to the .ssh directory on your local machine.&lt;br&gt;
Location:&lt;br&gt;
plaintext&lt;code&gt;C:\Users\tarik\.ssh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Expected Files: Look for the id_rsa.pub file. If it exists, your key was created successfully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Log In to Your VPS Server&lt;/strong&gt;&lt;br&gt;
Use the following command to log in to your VPS server. This initial login will still require your password.&lt;br&gt;
bash&lt;br&gt;
&lt;code&gt;ssh root@your_vps_ip&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: Replace your_vps_ip with the actual IP address of your VPS server.&lt;br&gt;
First-Time Login:&lt;br&gt;
You may be prompted to verify the server’s fingerprint. Type yes to continue.&lt;br&gt;
Enter your VPS password when prompted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Check or Create the .ssh Directory on the VPS&lt;/strong&gt;&lt;br&gt;
Once logged in, check if the .ssh directory exists on your VPS server.&lt;br&gt;
Check for .ssh Directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ls -a&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Explanation: This command lists all files, including hidden ones (files beginning with a dot, like .ssh).&lt;br&gt;
Or Use:&lt;br&gt;
&lt;code&gt;ls -ld ~/.ssh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Output if .ssh Exists:&lt;br&gt;
plaintext&lt;br&gt;
drwx------ 2 user user 4096 Aug 24 12:34 /root/.ssh&lt;/p&gt;

&lt;p&gt;Output if .ssh Does Not Exist:&lt;br&gt;
ls: cannot access '/root/.ssh': No such file or directory&lt;/p&gt;

&lt;p&gt;Create the .ssh Directory (If Needed): If the .ssh directory does not exist, create it with the following command:&lt;br&gt;
&lt;code&gt;mkdir -p ~/.ssh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Set Correct Permissions:&lt;br&gt;
chmod 700 ~/.ssh&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Explanation:&lt;/em&gt;&lt;br&gt;
mkdir -p ~/.ssh: Creates the .ssh directory, including any necessary parent directories.&lt;br&gt;
chmod 700 ~/.ssh: Sets the directory's permissions so only the owner (you) can read, write, and execute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Copy Your Public Key to the VPS&lt;/strong&gt;&lt;br&gt;
Now, copy your public key (id_rsa.pub) from your Windows machine to the VPS server. This step allows passwordless authentication.&lt;br&gt;
Command:&lt;br&gt;
`:=&amp;gt;nano ~/.ssh/authorized_keys&lt;br&gt;
=&amp;gt;Add the new key to the file by pasting it at the end of the file on a new line.&lt;/p&gt;

&lt;p&gt;=&amp;gt;Save and exit the file in Nano:&lt;/p&gt;

&lt;p&gt;Press Ctrl + O to save.&lt;br&gt;
Press Enter to confirm the file name.&lt;br&gt;
Press Ctrl + X to exit.`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Log In Without a Password&lt;/strong&gt;&lt;br&gt;
Now, you should be able to log in to your VPS server without entering a password.&lt;br&gt;
Command:&lt;br&gt;
&lt;code&gt;ssh root@74.208.202.89&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If everything is set up correctly, you’ll be logged in without needing to enter a password.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>MongoDB Schema Design, Indexes &amp; More Best Practices</title>
      <dc:creator>Md.Tarikul</dc:creator>
      <pubDate>Tue, 16 Jul 2024 02:49:16 +0000</pubDate>
      <link>https://dev.to/tarikul01/mongodb-schema-design-indexes-more-best-practices-3p75</link>
      <guid>https://dev.to/tarikul01/mongodb-schema-design-indexes-more-best-practices-3p75</guid>
      <description>&lt;p&gt;&lt;strong&gt;Schema Design Approaches – Relational vs. MongoDB&lt;/strong&gt;:&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Relational Databases:&lt;/strong&gt;&lt;/em&gt; Best for applications requiring complex queries, transactions, and data integrity. Ideal for structured data and systems where schema stability is important (e.g., financial applications, ERP systems).&lt;br&gt;
&lt;strong&gt;&lt;em&gt;MongoDB:&lt;/em&gt;&lt;/strong&gt; Best for applications requiring scalability, flexibility, and rapid development. Ideal for handling large volumes of unstructured or semi-structured data, real-time analytics, and applications where data structures evolve frequently (e.g., content management systems, IoT applications).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Embedding vs. Referencing:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Embedding&lt;/strong&gt;&lt;br&gt;
Example:&lt;br&gt;
Imagine a blog application where each post has comments.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
    "_id": 1,&lt;br&gt;
    "title": "First Post",&lt;br&gt;
    "content": "This is the content of the first post",&lt;br&gt;
    "comments": [&lt;br&gt;
        {&lt;br&gt;
            "user": "Alice",&lt;br&gt;
            "comment": "Great post!",&lt;br&gt;
            "date": "2024-07-16"&lt;br&gt;
        },&lt;br&gt;
        {&lt;br&gt;
            "user": "Bob",&lt;br&gt;
            "comment": "Thanks for sharing!",&lt;br&gt;
            "date": "2024-07-17"&lt;br&gt;
        }&lt;br&gt;
    ]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Performance: Faster read operations since related data is stored together.&lt;br&gt;
Atomicity: Updates to a document are atomic, ensuring consistency.&lt;br&gt;
Simplicity: Easy to manage and query related data within a single document.&lt;br&gt;
&lt;strong&gt;Limitations:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Document Size: Limited to 16 MB, so embedding large amounts of related data can exceed this limit.&lt;br&gt;
Data Redundancy: Duplicating data in multiple places can lead to inconsistencies and increased storage usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Referencing&lt;/strong&gt;&lt;br&gt;
Example:&lt;br&gt;
Using the same blog application, comments are stored in a separate collection.&lt;/p&gt;

&lt;p&gt;Posts Collection:&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "_id": 1,&lt;br&gt;
    "title": "First Post",&lt;br&gt;
    "content": "This is the content of the first post",&lt;br&gt;
    "comments": [&lt;br&gt;
        101,&lt;br&gt;
        102&lt;br&gt;
    ]&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Comments Collection:&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "_id": 101,&lt;br&gt;
    "user": "Alice",&lt;br&gt;
    "comment": "Great post!",&lt;br&gt;
    "date": "2024-07-16",&lt;br&gt;
    "postId": 1&lt;br&gt;
}&lt;br&gt;
{&lt;br&gt;
    "_id": 102,&lt;br&gt;
    "user": "Bob",&lt;br&gt;
    "comment": "Thanks for sharing!",&lt;br&gt;
    "date": "2024-07-17",&lt;br&gt;
    "postId": 1&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Flexibility: No size limit issues as comments grow.&lt;br&gt;
Data Normalization: Reduces data redundancy and potential inconsistencies.&lt;br&gt;
Scalability: Easier to manage large volumes of related data.&lt;br&gt;
&lt;strong&gt;Limitations:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Complexity: More complex queries to fetch related data, requiring joins.&lt;br&gt;
Performance: Slower read operations since data is spread across multiple documents.&lt;br&gt;
Atomicity: Updates to related data across multiple documents are not atomic, which can lead to inconsistencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recap:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One-to-One - Prefer key value pairs within the document&lt;/li&gt;
&lt;li&gt;One-to-Few - Prefer embedding&lt;/li&gt;
&lt;li&gt;One-to-Many - Prefer embedding&lt;/li&gt;
&lt;li&gt;One-to-Squillions - Prefer Referencing&lt;/li&gt;
&lt;li&gt;Many-to-Many - Prefer Referencing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;General Rules for MongoDB Schema Design:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Rule 1:&lt;br&gt;
Favor embedding unless there is a compelling reason not to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rule 2:&lt;br&gt;
Needing to access an object on its own is a compelling reason not to embed it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rule 3:&lt;br&gt;
Avoid joins and lookups if possible, but don't be afraid if they can provide a better schema design.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rule 4:&lt;br&gt;
Arrays should not grow without bound. If there are more than a couple of hundred documents on the many side, don't embed them; if there are more than a few thousand documents on the many side, don't use an array of ObjectID references. High-cardinality arrays are a compelling reason not to embed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rule 5: &lt;br&gt;
As always, with MongoDB, how you model your data depends entirely on your particular application's data access patterns. You want to structure your data to match the ways that your application queries and updates it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Relationships&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One-to-One:
&lt;/h2&gt;

&lt;p&gt;Let's take a look at our User document. This example has some great one-to-one data in it. For example, in our system, one user can only have one name. So, this would be an example of a one-to-one relationship. We can model all one-to-one data as key-value pairs in our database.&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "_id": "ObjectId('AAA')",&lt;br&gt;
    "name": "Joe Karlsson",&lt;br&gt;
    "company": "MongoDB",&lt;br&gt;
    "twitter": "@JoeKarlsson1",&lt;br&gt;
    "twitch": "joe_karlsson",&lt;br&gt;
    "tiktok": "joekarlsson",&lt;br&gt;
    "website": "joekarlsson.com"&lt;br&gt;
&lt;/code&gt;}&lt;/p&gt;

&lt;h2&gt;
  
  
  One-to-Few:
&lt;/h2&gt;

&lt;p&gt;Okay, now let's say that we are dealing a small sequence of data that's associated with our users. For example, we might need to store several addresses associated with a given user. It's unlikely that a user for our application would have more than a couple of different addresses. For relationships like this, we would define this as a one-to-few relationship.&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "_id": "ObjectId('AAA')",&lt;br&gt;
    "name": "Joe Karlsson",&lt;br&gt;
    "company": "MongoDB",&lt;br&gt;
    "twitter": "@JoeKarlsson1",&lt;br&gt;
    "twitch": "joe_karlsson",&lt;br&gt;
    "tiktok": "joekarlsson",&lt;br&gt;
    "website": "joekarlsson.com",&lt;br&gt;
    "addresses": [&lt;br&gt;
        { "street": "123 Sesame St", "city": "Anytown", "cc": "USA" },  &lt;br&gt;
        { "street": "123 Avenue Q",  "city": "New York", "cc": "USA" }&lt;br&gt;
    ]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One-to-Many:
&lt;/h2&gt;

&lt;p&gt;Alright, let's say that you are building a product page for an e-commerce website, and you are going to have to design a schema that will be able to show product information. In our system, we save information about all the many parts that make up each product for repair services. How would you design a schema to save all this data, but still make your product page performant? You might want to consider a one-to-many schema since your one product is made up of many parts.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Product&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "name": "left-handed smoke shifter",&lt;br&gt;
    "manufacturer": "Acme Corp",&lt;br&gt;
    "catalog_number": "1234",&lt;br&gt;
    "parts": ["ObjectID('AAAA')", "ObjectID('BBBB')", "ObjectID('CCCC')"]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Parts&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "_id" : "ObjectID('AAAA')",&lt;br&gt;
    "partno" : "123-aff-456",&lt;br&gt;
    "name" : "#4 grommet",&lt;br&gt;
    "qty": "94",&lt;br&gt;
    "cost": "0.94",&lt;br&gt;
    "price":" 3.99"&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  One-to-Squillions:
&lt;/h2&gt;

&lt;p&gt;What if we have a schema where there could be potentially millions of subdocuments, or more? That's when we get to the one-to-squillions schema. And, I know what you're thinking: &lt;em&gt;Is squillions a real word?&lt;/em&gt; &lt;br&gt;
And the answer is yes, it is a real word.&lt;br&gt;
Let's imagine that you have been asked to create a server logging application. Each server could potentially save a massive amount of data, depending on how verbose you're logging and how long you store server logs for.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;hosts&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "_id": ObjectID("AAAB"),&lt;br&gt;
    "name": "goofy.example.com",&lt;br&gt;
    "ipaddr": "127.66.66.66"&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Log messages&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "time": ISODate("2014-03-28T09:42:41.382Z"),&lt;br&gt;
    "message": "cpu is on fire!",&lt;br&gt;
    "host": ObjectID("AAAB")&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Many-to-Many:
&lt;/h2&gt;

&lt;p&gt;The last schema design pattern we are going to be covering in this post is the many-to-many relationship. This is another very common schema pattern that we see all the time in relational and MongoDB schema designs. For this pattern, let's imagine that we are building a to-do application. In our app, a user may have many tasks and a task may have many users assigned to it.&lt;br&gt;
todo_9ddb687d61&lt;br&gt;
In order to preserve these relationships between users and tasks, there will need to be references from the one user to the many tasks and references from the one task to the many users. Let's look at how this could work for a to-do list application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;users:&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "_id": ObjectID("AAF1"),&lt;br&gt;
    "name": "Kate Monster",&lt;br&gt;
    "tasks": [ObjectID("ADF9"), ObjectID("AE02"), ObjectID("AE73")]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;tasks:&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
    "_id": ObjectID("ADF9"),&lt;br&gt;
    "description": "Write blog post about MongoDB schema design",&lt;br&gt;
    "due_date": ISODate("2014-04-01"),&lt;br&gt;
    "owners": [ObjectID("AAF1"), ObjectID("BB3G")]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Optimising query patterns&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Optimizing your query patterns is crucial for reducing execution time and resource usage:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Projection:&lt;br&gt;
Use projection to limit the fields returned by your queries, minimizing data transfer and processing load. Also, it’s better to exclude _id with 0 (false) if it’s not a field pertaining to the application — i.e., an auto-generated field by MongoDB. &lt;code&gt;db.collection.find({ field: value }, { field1: 1, field2: 1 })&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Aggregation framework:&lt;br&gt;
Leverage MongoDB's &lt;br&gt;
aggregation framework for complex data processing. Ensure aggregations utilize indexed fields where possible.&lt;br&gt;
&lt;code&gt;db.collection.aggregate([ { $match: { field: value } }, { $group: { _id: "$field", total: { $sum: "$amount" } } } ])&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid $where:&lt;br&gt;
The $where operator can be slow and resource-intensive. Use it sparingly and only when necessary. Instead, the use of $expr with aggregation operators that do not use JavaScript (i.e., non-$function and non-$accumulator operators) is faster than $where because it does not execute JavaScript and is preferable, when possible. However, if you must create custom expressions, $function is preferred over $where.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;As you can see, there are a ton of different ways to express your schema design, by going beyond normalizing your data like you might be used to doing in SQL. By taking advantage of embedding data within a document or referencing documents using the $lookup operator, you can make some truly powerful, scalable, and efficient database queries that are completely unique to your application. In fact, we are only barely able to scratch the surface of all the ways that you could model your data in MongoDB.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
