-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.xml
179 lines (179 loc) · 478 KB
/
rss.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>The Data Column Blog</title>
<link>https://ivishalgandhi.github.io/</link>
<description>The Data Column Blog</description>
<lastBuildDate>Sat, 21 Sep 2024 00:00:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
<language>en</language>
<item>
<title><![CDATA[BI as Code]]></title>
<link>https://ivishalgandhi.github.io/bi-as-code</link>
<guid>bi-as-code</guid>
<pubDate>Sat, 21 Sep 2024 00:00:00 GMT</pubDate>
<description><![CDATA[In today's data-driven world, Business Intelligence (BI) has become indispensable for organizations seeking to gain insights from their data. Traditionally, BI solutions have been associated with hefty price tags and complex implementations. However, the landscape is rapidly changing with the emergence of open-source BI solutions that are flexible in adoption, run on commodity hardware, integrate with multiple existing data sources, and leverage a code-first approach. This shift is not only making BI more accessible but also more flexible, innovative, and powerful than ever before. Open source BI solutions are democratizing data analytics, allowing organizations of all sizes to harness the power of their data. Furthermore, the integration of cutting-edge, in-memory database technologies like DuckDB is supercharging these solutions. DuckDB's ability to process large datasets with lightning speed, coupled with its low memory footprint and seamless integration capabilities, is enabling real-time analytics and complex data manipulations that were once the domain of expensive, enterprise-grade systems. This powerful combination of open-source BI tools and efficient in-memory databases is truly revolutionizing the way organizations approach data analysis, making sophisticated BI capabilities accessible and affordable for businesses of all sizes.]]></description>
<content:encoded><![CDATA[<p>In today's data-driven world, Business Intelligence (BI) has become indispensable for organizations seeking to gain insights from their data. Traditionally, BI solutions have been associated with hefty price tags and complex implementations. However, the landscape is rapidly changing with the emergence of open-source BI solutions that are flexible in adoption, run on commodity hardware, integrate with multiple existing data sources, and leverage a code-first approach. This shift is not only making BI more accessible but also more flexible, innovative, and powerful than ever before. Open source BI solutions are democratizing data analytics, allowing organizations of all sizes to harness the power of their data. Furthermore, the integration of cutting-edge, in-memory database technologies like <a href="https://duckdb.org" target="_blank" rel="noopener noreferrer">DuckDB</a> is supercharging these solutions. DuckDB's ability to process large datasets with lightning speed, coupled with its low memory footprint and seamless integration capabilities, is enabling real-time analytics and complex data manipulations that were once the domain of expensive, enterprise-grade systems. This powerful combination of open-source BI tools and efficient in-memory databases is truly revolutionizing the way organizations approach data analysis, making sophisticated BI capabilities accessible and affordable for businesses of all sizes.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="code-first-approach-in-bi-a-paradigm-shift">Code-First Approach in BI: A Paradigm Shift<a class="hash-link" href="#code-first-approach-in-bi-a-paradigm-shift" title="Direct link to heading"></a></h2><p>The code-first approach to BI represents a significant departure from traditional drag-and-drop interfaces. By using code to build BI solutions, professionals can:</p><ul><li>Create more customized and flexible dashboards</li><li>Version control their BI projects using Git</li><li>Automate data pipelines and report generation</li><li>Integrate BI seamlessly into existing software development workflows</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="open-source-solutions-leading-the-way">Open Source Solutions Leading the Way<a class="hash-link" href="#open-source-solutions-leading-the-way" title="Direct link to heading"></a></h2><h3 class="anchor anchorWithStickyNavbar_LWe7" id="evidence"><a href="https://evidence.dev/" target="_blank" rel="noopener noreferrer">Evidence</a><a class="hash-link" href="#evidence" title="Direct link to heading"></a></h3><p>Evidence is a groundbreaking open-source project that allows users to create data visualizations and dashboards using SQL and Markdown. It generates static websites from these files, making it easy to deploy and share insights across organization.</p><p>Key features of Evidence include:</p><ul><li>SQL-based data querying</li><li>Markdown for report structure and narrative</li><li>Built-in charting capabilities</li><li>Version control friendly</li></ul><h3 class="anchor anchorWithStickyNavbar_LWe7" id="streamlit"><a href="https://streamlit.io/" target="_blank" rel="noopener noreferrer">Streamlit</a><a class="hash-link" href="#streamlit" title="Direct link to heading"></a></h3><p>Streamlit has gained significant traction in the data science community for its ability to turn data scripts into shareable web apps quickly. While not exclusively a BI tool, Streamlit's flexibility makes it an excellent choice for creating interactive data applications.</p><p>Streamlit shines in:</p><ul><li>Rapid <strong>prototyping</strong> of data apps</li><li>Easy integration with Python <strong>data science</strong> libraries</li><li>Real-time interactivity</li></ul><h3 class="anchor anchorWithStickyNavbar_LWe7" id="rill"><a href="https://rilldata.com/" target="_blank" rel="noopener noreferrer">RILL</a><a class="hash-link" href="#rill" title="Direct link to heading"></a></h3><p>RILL is another promising open-source BI platform that focuses on real-time analytics. It allows users to build live dashboards and reports using SQL, making it an excellent choice for organizations that need up-to-the-minute insights.</p><p>RILL's strengths include:</p><ul><li><strong>Real-time</strong> data processing</li><li><strong>SQL-based</strong> analysis</li><li><strong>Scalable</strong> architecture for large datasets</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="duckdb---the-power-of-in-process-databases"><a href="https://duckdb.org/" target="_blank" rel="noopener noreferrer">DuckDB</a> - The Power of In-Process Databases<a class="hash-link" href="#duckdb---the-power-of-in-process-databases" title="Direct link to heading"></a></h2><p>One of the key enablers of this BI-as-Code revolution is the advent of high-performance, in-process databases like DuckDB. These databases offer several advantages:</p><ul><li><strong>Speed</strong>: In-process databases eliminate network overhead, resulting in lightning-fast query execution.</li><li><strong>Simplicity</strong>: They can be embedded directly into applications, simplifying deployment and maintenance.</li><li><strong>Versatility</strong>: DuckDB, for instance, can efficiently handle various data formats, from CSV to Parquet.</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a class="hash-link" href="#conclusion" title="Direct link to heading"></a></h2><p>The landscape of Business Intelligence is evolving rapidly, with open-source, code-based solutions leading the charge. Tools like Evidence, Streamlit, and RILL, combined with efficient databases like DuckDB, are proving that powerful, real-time BI doesn't have to come with a hefty price tag. As organizations continue to recognize the value of data-driven decision-making, the adoption of these open-source BI solutions is likely to accelerate. The future of BI is not just about making data accessible; it's about making powerful analytics tools accessible to all. Whether you're a startup looking to bootstrap your analytics capabilities or an enterprise seeking to complement existing solutions, the world of open-source BI as code offers exciting possibilities.</p>]]></content:encoded>
<category>evidence</category>
<category>streamlit</category>
<category>rill</category>
<category>bi-as-a-code</category>
</item>
<item>
<title><![CDATA[The Transformation of API Clients - A Strategic Analysis]]></title>
<link>https://ivishalgandhi.github.io/api-clients</link>
<guid>api-clients</guid>
<pubDate>Sun, 25 Aug 2024 00:00:00 GMT</pubDate>
<description><![CDATA[The world of API development tools is experiencing a major shift, fueled by new technologies and changing developer preferences. In this blog post, I dive into the dynamic ecosystem of API clients, highlighting well-known names like Postman and Insomnia, alongside innovative open-source alternates such as Bruno and HURL. We'll explore how these developments are impacting enterprise IT strategies, boosting developer productivity, and enhancing overall business agility.]]></description>
<content:encoded><![CDATA[<p>The world of API development tools is experiencing a major shift, fueled by new technologies and changing developer preferences. In this blog post, I dive into the dynamic ecosystem of API clients, highlighting well-known names like Postman and Insomnia, alongside innovative open-source alternates such as <a href="https://usebruno.com" target="_blank" rel="noopener noreferrer">Bruno</a> and <a href="https://hurl.dev" target="_blank" rel="noopener noreferrer">HURL</a>. We'll explore how these developments are impacting enterprise IT strategies, boosting developer productivity, and enhancing overall business agility.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="analysis">Analysis<a class="hash-link" href="#analysis" title="Direct link to heading"></a></h2><h3 class="anchor anchorWithStickyNavbar_LWe7" id="postman">Postman<a class="hash-link" href="#postman" title="Direct link to heading"></a></h3><ul><li><strong>Market Position</strong>: Industry leader with over 20 million users globally</li><li><strong>Recent Developments</strong>: Announced in May 2023 the gradual phasing out of the Scratch Pad model with offline capabilities</li><li><strong>Challenges</strong>:<ul><li>Shift towards cloud-based functionality raises data privacy concerns</li><li>Potential limitations for users in high-security environments</li></ul></li></ul><h3 class="anchor anchorWithStickyNavbar_LWe7" id="insomnia">Insomnia<a class="hash-link" href="#insomnia" title="Direct link to heading"></a></h3><ul><li><strong>Market Position</strong>: Popular alternative to Postman</li><li><strong>Recent Developments</strong>: Version 8.0 (September 2023) intensified cloud reliance</li><li><strong>Challenges</strong>:<ul><li>Mandatory login for full functionality</li><li>Limited offline capabilities</li></ul></li></ul><p>These developments in both Postman and Insomnia highlight a growing industry trend towards cloud-centric models, which may not align with all enterprise security and privacy requirements.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="transformative-trends-in-api-clients">Transformative Trends in API Clients<a class="hash-link" href="#transformative-trends-in-api-clients" title="Direct link to heading"></a></h2><ul><li><p><strong>Shift from GUI to Code-First Approaches</strong></p><ul><li>Tools like Bruno and HURL represent a move towards more developer-centric, code-based workflows. This aligns with the broader industry trend of "infrastructure as code"</li></ul></li><li><p><strong>Emphasis on Version Control and Collaboration</strong></p><ul><li>Git-centric approaches (e.g., Bruno) facilitate better version control and team collaboration</li><li>This trend mirrors the evolution seen in other areas of software development</li></ul></li><li><p><strong>Balancing Cloud Features with Data Privacy</strong></p><ul><li>While Postman and Insomnia move towards cloud-centric models, tools like Bruno and HURL offer local-first alternatives</li><li>This dichotomy reflects the ongoing tension between collaboration features and data security concerns</li></ul></li><li><p><strong>Simplification and Specialization</strong></p><ul><li>HURL's focus on simplicity and CI/CD integration represents a trend towards specialized, task-specific tools</li><li>This contrasts with the "swiss army knife" approach of more comprehensive platforms like Postman</li></ul></li><li><p><strong>Open Source vs. Proprietary Solutions</strong></p><ul><li>The rise of open-source alternatives challenges the dominance of proprietary tools</li><li>This shift may impact pricing models and feature development in the industry</li></ul></li><li><p><strong>Integration with Generative AI</strong></p><ul><li>Emerging tools like Bruno and Hurl are well-positioned to leverage Generative AI capabilities</li><li>This integration can significantly enhance developer productivity and API testing efficiency</li></ul></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="strategic-implications-for-enterprises">Strategic Implications for Enterprises<a class="hash-link" href="#strategic-implications-for-enterprises" title="Direct link to heading"></a></h2><ul><li><p><strong>Reevaluation of Tool Stack</strong></p><ul><li>Organizations need to reassess their API development toolchain in light of these new options</li><li>Consider the balance between comprehensive platforms and specialized tools</li></ul></li><li><p><strong>Data Privacy and Security</strong></p><ul><li>The shift towards cloud-based models necessitates a careful evaluation of data handling practices</li><li>Local-first tools may offer advantages for organizations with strict security requirements</li></ul></li><li><p><strong>Developer Productivity and Workflow</strong></p><ul><li>Code-first approaches may enhance productivity for technically proficient teams</li><li>However, GUI-based tools might remain preferable for less technical users or for complex scenarios</li></ul></li><li><p><strong>Integration with DevOps Practices</strong></p><ul><li>Tools that align well with version control and CI/CD pipelines (e.g., Bruno, HURL) may streamline DevOps workflows</li><li>This could lead to faster development cycles and more reliable API testing</li></ul></li><li><p><strong>Cost Considerations</strong></p><ul><li>Open-source tools may reduce licensing costs but could increase support and training expenses</li><li>Enterprises must conduct a thorough TCO analysis when considering new tools</li></ul></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="generative-ai-a-game-changer-for-api-clients">Generative AI: A Game-Changer for API Clients<a class="hash-link" href="#generative-ai-a-game-changer-for-api-clients" title="Direct link to heading"></a></h2><p>The integration of Generative AI with API clients like Hurl and Bruno presents exciting possibilities for enhancing developer productivity and streamlining API development processes. Here are some potential applications and benefits:</p><ol><li><p><strong>Automated Test Case Generation</strong></p><ul><li>Generative AI could analyze API specifications and automatically generate comprehensive test cases in Hurl's simple text format or Bruno's JSON-based format.</li><li>Example: For a complex e-commerce API, the AI could generate tests covering various scenarios like product searches, order placements, and payment processing, significantly reducing manual test creation time.</li></ul></li><li><p><strong>Intelligent Request Crafting</strong></p><ul><li>AI can assist in crafting sophisticated API requests based on natural language descriptions.</li><li>Example: A developer could input "Create a request to retrieve all orders placed in the last 30 days for premium customers," and the AI would generate the appropriate API request in Hurl or Bruno syntax.</li></ul></li><li><p><strong>Dynamic Mock Response Generation</strong></p><ul><li>Generative AI can create realistic mock responses based on API specifications and historical data.</li><li>Example: For a weather API, the AI could generate diverse mock responses reflecting various weather conditions, helping developers test their applications more thoroughly.</li></ul></li><li><p><strong>Natural Language Query Translation</strong></p><ul><li>AI can translate natural language queries into API requests, making API exploration more accessible to non-technical stakeholders.</li><li>Example: A product manager could ask, "What were our top-selling products last quarter?" and the AI would translate this into the appropriate API query in Hurl or Bruno format.</li></ul></li><li><p><strong>Automated Documentation and Comment Generation</strong></p><ul><li>AI can analyze API collections and generate human-readable documentation or add contextual comments to requests.</li><li>Example: The AI could review a set of Bruno collection files and generate comprehensive Markdown documentation explaining each endpoint's purpose, parameters, and example uses.</li></ul></li><li><p><strong>Intelligent API Diff and Changelog Generation</strong></p><ul><li>When integrated with version control systems, AI could analyze changes in API definitions and generate meaningful changelogs.</li><li>Example: After modifying several endpoints in a Bruno collection, the AI could generate a concise yet comprehensive summary of the changes, highlighting potential breaking changes or new features.</li></ul></li></ol><p>By leveraging these AI capabilities, tools like Hurl and Bruno can offer developers a more intuitive, efficient, and powerful API development experience. This integration has the potential to significantly reduce development time, improve code quality, and enhance overall API design and testing processes.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="bruno-and-hurl-a-paradigm-shift">Bruno and HURL: A Paradigm Shift<a class="hash-link" href="#bruno-and-hurl-a-paradigm-shift" title="Direct link to heading"></a></h2><p>Bruno and HURL represents a significant shift in how developers interact with APIs. Its key differentiators include:</p><ol><li><p><strong>Git-Centric Workflow</strong>: Bruno's file-based approach aligns seamlessly with version control systems, a critical factor for maintaining code integrity and collaboration.</p></li><li><p><strong>Resource Efficiency</strong>: As a lightweight tool, Bruno promises improved performance, particularly valuable in resource-constrained environments.</p></li><li><p><strong>Open-Source Flexibility</strong>: The ability to customize and extend the tool can lead to better alignment with specific organizational needs.</p></li><li><p><strong>Enhanced Security Posture</strong>: Bruno's local-first approach addresses data privacy concerns, a growing priority in our industry.</p></li></ol><h2 class="anchor anchorWithStickyNavbar_LWe7" id="case-study-api-testing-efficiency">Case Study: API Testing Efficiency<a class="hash-link" href="#case-study-api-testing-efficiency" title="Direct link to heading"></a></h2><p>To illustrate the potential impact, let's consider a brief case study using a common scenario: weather data retrieval.</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="scenario-integrating-weather-data-into-a-corporate-dashboard">Scenario: Integrating Weather Data into a Corporate Dashboard<a class="hash-link" href="#scenario-integrating-weather-data-into-a-corporate-dashboard" title="Direct link to heading"></a></h3><p>Both Postman and Bruno can efficiently handle this task. Here's a high-level comparison:</p><table><thead><tr><th>Aspect</th><th>Postman</th><th>Bruno</th></tr></thead><tbody><tr><td>Setup Time</td><td>GUI-based, potentially slower</td><td>File-based, potentially faster</td></tr><tr><td>Version Control</td><td>Requires manual export</td><td>Native git integration</td></tr><tr><td>Team Collaboration</td><td>Cloud-based sharing</td><td>Git-based collaboration</td></tr><tr><td>Learning Curve</td><td>Steeper due to extensive features</td><td>Shallower, focuses on essentials</td></tr></tbody></table><p>While Postman offers a more comprehensive feature set, Bruno's simplicity and git-integration could lead to faster setup times and more streamlined collaboration for certain teams.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a class="hash-link" href="#conclusion" title="Direct link to heading"></a></h2><p>The rise of Hurl and Bruno signifies a broader trend towards simpler, more developer-centric tools in the API ecosystem. While it may not entirely displace established players like Postman, it represents an important shift that we as IT leaders need to be aware of and prepared for.</p><p>By staying informed and adaptable, we can ensure that our organizations are well-positioned to leverage the best tools for our specific needs, ultimately driving innovation and maintaining our competitive edge in the digital landscape.</p>]]></content:encoded>
<category>bruno</category>
<category>hurl</category>
<category>postman</category>
<category>insomnia</category>
<category>api</category>
</item>
<item>
<title><![CDATA[Essential Skills and Tools for Aspiring Software Developers and Database Engineers]]></title>
<link>https://ivishalgandhi.github.io/essential-skills</link>
<guid>essential-skills</guid>
<pubDate>Sun, 21 Jan 2024 00:00:00 GMT</pubDate>
<description><![CDATA[Introduction]]></description>
<content:encoded><![CDATA[<h2 class="anchor anchorWithStickyNavbar_LWe7" id="introduction">Introduction<a class="hash-link" href="#introduction" title="Direct link to heading"></a></h2><p>Starting a career as a software developer in the fast-paced and ever-evolving IT industry can be both exciting and challenging. To thrive in this field, it is essential to equip yourself with the right skills, tools, and technologies. In this article, we will highlight key areas of focus that will help you establish a solid foundation as a software developer.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="data-structures-and-algorithms">Data Structures and Algorithms<a class="hash-link" href="#data-structures-and-algorithms" title="Direct link to heading"></a></h2><p>Data structures and algorithms are fundamental concepts in computer science. They are used to organize and manipulate data efficiently. As a software developer, you will need to understand how data structures and algorithms work to solve problems and build applications. Learn about common data structures such as arrays, linked lists, stacks, queues, trees, and graphs. Familiarize yourself with common algorithms such as sorting, searching, and graph traversal. This knowledge will help you write efficient code and optimize your applications.</p><p>Resources to learn Data Structures and Algorithms:</p><ul><li><a href="https://www.coursera.org/specializations/data-structures-algorithms" target="_blank" rel="noopener noreferrer">Data Structures and Algorithms Specialization</a> by UC San Diego</li><li><a href="https://www.amazon.com/Algorithmic-Thinking-Problem-Based-Daniel-Zingaro/dp/1718500807/ref=sr_1_1?keywords=Algorithmic+thinking&qid=1705894084&sr=8-1" target="_blank" rel="noopener noreferrer">Algorithmic Thinking: A Problem-Based Introduction</a> by Daniel Zingaro</li><li><a href="https://www.amazon.com/Introduction-Algorithms-3rd-MIT-Press/dp/0262033844" target="_blank" rel="noopener noreferrer">Introduction to Algorithms</a> by Thomas H. Cormen</li><li><a href="https://www.coursera.org/learn/algorithms-part1" target="_blank" rel="noopener noreferrer">Algorithms, Part I</a> by Princeton University on Coursera</li><li><a href="https://www.coursera.org/learn/algorithms-part2" target="_blank" rel="noopener noreferrer">Algorithms, Part II</a> by Princeton University on Coursera</li><li><a href="https://www.amazon.com/Structures-Algorithms-Python-Michael-Goodrich/dp/1118290275" target="_blank" rel="noopener noreferrer">Data Structures and Algorithms in Python</a> by Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser</li><li><a href="https://www.geeksforgeeks.org/data-structures/" target="_blank" rel="noopener noreferrer">GeeksforGeeks</a> - A computer science portal with resources on various topics including data structures and algorithms</li><li><a href="https://leetcode.com/" target="_blank" rel="noopener noreferrer">LeetCode</a> - A platform for preparing technical coding interviews with a focus on algorithms and data structures problems</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="programming-languages">Programming Languages<a class="hash-link" href="#programming-languages" title="Direct link to heading"></a></h2><p>Programming languages are the building blocks of software development. As a software developer, you will need to learn multiple programming languages to build applications and solve problems. While there are many programming languages to choose from, it is essential to focus on the ones that are in demand and align with your career goals. Learn about popular programming languages such as Go, Python, Rust, and Javascript. Familiarize yourself with their syntax, features, and use cases. This knowledge will enable you to write clean, maintainable, and extensible code.</p><p><a href="https://survey.stackoverflow.co/2023/#section-admired-and-desired-programming-scripting-and-markup-languages" target="_blank" rel="noopener noreferrer">Stack Overflow Most Admired and Desired Programming Languages 2023</a></p><p>Resources to learn Go:</p><ul><li><a href="https://www.amazon.com/Go-Programming-Language-Addison-Wesley-Professional/dp/0134190440" target="_blank" rel="noopener noreferrer">The Go Programming Language</a> by Alan A. A. Donovan and Brian W. Kernighan</li><li><a href="https://gobyexample.com/" target="_blank" rel="noopener noreferrer">Go by Example</a></li><li><a href="https://tour.golang.org/welcome/1" target="_blank" rel="noopener noreferrer">A Tour of Go</a></li></ul><p>Resources to learn Rust:</p><ul><li><a href="https://www.amazon.com/Rust-Programming-Language-Steve-Klabnik/dp/1593278284" target="_blank" rel="noopener noreferrer">The Rust Programming Language</a> by Steve Klabnik and Carol Nichols</li><li><a href="https://doc.rust-lang.org/rust-by-example/" target="_blank" rel="noopener noreferrer">Rust by Example</a></li><li><a href="https://github.com/rust-lang/rustlings" target="_blank" rel="noopener noreferrer">Rustlings</a></li></ul><p>Resources to learn Python:</p><ul><li><a href="https://www.amazon.com/Python-Crash-Course-2nd-Edition/dp/1593279280" target="_blank" rel="noopener noreferrer">Python Crash Course</a> by Eric Matthes</li><li><a href="https://automatetheboringstuff.com/" target="_blank" rel="noopener noreferrer">Automate the Boring Stuff with Python</a></li><li><a href="https://learnpythonthehardway.org/" target="_blank" rel="noopener noreferrer">Learn Python the Hard Way</a></li></ul><p>Roadmaps to learn Go, Rust, and Python:</p><ul><li><a href="https://roadmap.sh/golang" target="_blank" rel="noopener noreferrer">Go Developer Roadmap</a></li><li><a href="https://roadmap.sh/rust" target="_blank" rel="noopener noreferrer">Rust Developer Roadmap</a></li><li><a href="https://roadmap.sh/python" target="_blank" rel="noopener noreferrer">Python Developer Roadmap</a></li></ul><p>You can find an extensive range of developer roadmaps at <a href="http://roadmap.sh" target="_blank" rel="noopener noreferrer">Roadmap.sh</a>.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="design-patterns">Design Patterns<a class="hash-link" href="#design-patterns" title="Direct link to heading"></a></h2><p>Design patterns are reusable solutions to common problems in software development. They are used to solve problems and improve the quality of code. As a software developer, you will need to understand how design patterns work to build robust and scalable applications. Learn about common design patterns such as creational, structural, and behavioral patterns. Familiarize yourself with the SOLID principles of object-oriented design. This knowledge will enable you to write clean, maintainable, and extensible code.</p><p>Resources to learn Design Patterns:</p><ul><li><a href="https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612" target="_blank" rel="noopener noreferrer">Design Patterns: Elements of Reusable Object-Oriented Software</a> by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides</li><li><a href="https://www.amazon.com/Head-First-Design-Patterns-Brain-Friendly/dp/0596007124" target="_blank" rel="noopener noreferrer">Head First Design Patterns</a> by Eric Freeman and Elisabeth Robson</li><li><a href="https://refactoring.guru/design-patterns" target="_blank" rel="noopener noreferrer">Refactoring.Guru</a> - A website that explains 22 design patterns and 8 principles of object-oriented design in a simple and intuitive way</li><li><a href="https://sourcemaking.com/design_patterns" target="_blank" rel="noopener noreferrer">SourceMaking</a> - A resource for learning about design patterns, anti-patterns, and refactoring</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="cloud-native-development">Cloud Native Development<a class="hash-link" href="#cloud-native-development" title="Direct link to heading"></a></h2><p>Cloud native development is a software development approach that leverages cloud computing to build and deploy applications. It enables developers to focus on writing code instead of managing infrastructure. Learn about cloud computing concepts such as virtualization, containers, and serverless computing. Familiarize yourself with cloud platforms such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). This knowledge will enable you to build scalable and resilient applications.</p><p>Resources to learn Cloud Native Development:</p><ul><li><a href="https://www.amazon.com/Cloud-Native-Containers-Functions-Next-Generation/dp/1492040762" target="_blank" rel="noopener noreferrer">Cloud Native: Using Containers, Functions, and Data to Build Next-Generation Applications</a> by Boris Scholl, Trent Swanson, and Peter Jausovec</li><li><a href="https://www.amazon.com/Kubernetes-Running-Dive-Future-Infrastructure/dp/1492046531" target="_blank" rel="noopener noreferrer">Kubernetes: Up and Running: Dive into the Future of Infrastructure</a> by Brendan Burns, Joe Beda, and Kelsey Hightower</li><li><a href="https://www.amazon.com/Cloud-Native-DevOps-Kubernetes-Applications/dp/1492040762" target="_blank" rel="noopener noreferrer">Cloud Native DevOps with Kubernetes: Building, Deploying, and Scaling Modern Applications in the Cloud</a> by John Arundel and Justin Domingus</li><li><a href="https://learnk8s.io/" target="_blank" rel="noopener noreferrer">The Cloud Native Learning Resources</a> by Learnk8s</li><li><a href="https://www.cncf.io/" target="_blank" rel="noopener noreferrer">Cloud Native Computing Foundation</a> - The foundation hosts critical components of the global technology infrastructure, including Kubernetes, Prometheus, and Envoy</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="databases">Databases<a class="hash-link" href="#databases" title="Direct link to heading"></a></h2><p>Databases are used to store and retrieve data. As a software developer, you will need to understand how databases work to build applications that interact with them. Learn about relational databases such as MySQL and PostgreSQL, NoSQL databases such as MongoDB and Redis, and cloud databases such as Amazon DynamoDB and Google Cloud Firestore. Familiarize yourself with database design, data modeling, and query languages such as SQL. This knowledge will enable you to build robust and scalable applications.</p><p><a href="https://survey.stackoverflow.co/2023/#section-admired-and-desired-databases" target="_blank" rel="noopener noreferrer">StackOverflow Most Admired and Desired Databases 2023</a></p><p>Resources to learn Databases:</p><ul><li><a href="https://www.amazon.com/Database-Internals-Deep-Distributed-Systems/dp/1492040347" target="_blank" rel="noopener noreferrer">Database Internals: A Deep Dive into How Distributed Data Systems Work</a> by Alex Petrov</li><li><a href="https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321" target="_blank" rel="noopener noreferrer">Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems</a> by Martin Kleppmann</li><li><a href="https://www.amazon.com/Database-Design-Mere-Mortals-Hands/dp/0321884493" target="_blank" rel="noopener noreferrer">Database Design for Mere Mortals: A Hands-On Guide to Relational Database Design</a> by Michael J. Hernandez</li><li><a href="https://sqlzoo.net/" target="_blank" rel="noopener noreferrer">SQLZOO</a> - A website that provides interactive SQL tutorials and exercises</li><li><a href="https://sqlbolt.com/" target="_blank" rel="noopener noreferrer">SQLBolt</a> - A website that provides interactive SQL tutorials and exercises</li></ul><p>Don't underestimate the power of SQLite. It's a lightweight, file-based database that's great for small applications and prototyping. Also, consider exploring open-source databases like <a href="https://github.com/rqlite/rqlite" target="_blank" rel="noopener noreferrer">rqlite</a>, which is a lightweight, distributed relational database built on SQLite.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="distributed-systems">Distributed Systems<a class="hash-link" href="#distributed-systems" title="Direct link to heading"></a></h2><p>Distributed systems are groups of networked computers that interact with each other to achieve a common goal. Key concepts in distributed systems include consensus algorithms like <a href="https://raft.github.io/" target="_blank" rel="noopener noreferrer">RAFT</a>, and principles like the CAP Theorem.</p><p>Resources to learn Distributed Systems:</p><ul><li><a href="https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321" target="_blank" rel="noopener noreferrer">Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems</a> by Martin Kleppmann</li><li><a href="http://book.mixu.net/distsys/single-page.html" target="_blank" rel="noopener noreferrer">Distributed Systems for Fun and Profit</a> by Mikito Takada</li><li><a href="https://raft.github.io/" target="_blank" rel="noopener noreferrer">RAFT</a></li></ul><p>Understanding the CAP Theorem is crucial when working with distributed databases. It states that it's impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees: Consistency, Availability, and Partition tolerance.</p><ul><li><a href="https://www.ibm.com/cloud/learn/cap-theorem" target="_blank" rel="noopener noreferrer">CAP Theorem: Explained</a> by IBM Cloud Education</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="cicd-pipelines">CI/CD Pipelines<a class="hash-link" href="#cicd-pipelines" title="Direct link to heading"></a></h2><p>Continuous Integration (CI) and Continuous Delivery (CD) are software development practices that enable developers to build, test, and deploy code frequently and reliably. Learn about CI/CD pipelines and how they work. Familiarize yourself with popular CI/CD tools such as Jenkins, CircleCI, and Travis CI. This knowledge will enable you to automate the software development lifecycle and deliver high-quality software faster.</p><p>Resources to learn CI/CD:</p><ul><li><a href="https://www.amazon.com/Continuous-Delivery-Deployment-Automation-Addison-Wesley/dp/0321601912" target="_blank" rel="noopener noreferrer">Continuous Delivery: Reliable Software Releases through Build, Test, and Deployment Automation</a> by Jez Humble and David Farley</li><li><a href="https://docs.travis-ci.com/" target="_blank" rel="noopener noreferrer">Travis CI Documentation</a> - Comprehensive guide on how to use Travis CI</li><li><a href="https://docs.github.com/en/actions" target="_blank" rel="noopener noreferrer">GitHub Actions Documentation</a> - Learn how to automate, customize, and execute your software development workflows right in your repository with GitHub Actions</li></ul><p>Resources to learn Git:</p><ul><li><a href="https://git-scm.com/book/en/v2" target="_blank" rel="noopener noreferrer">Pro Git</a> by Scott Chacon and Ben Straub</li><li><a href="https://lab.github.com/" target="_blank" rel="noopener noreferrer">GitHub Learning Lab</a> - Interactive courses on Git and GitHub</li><li><a href="https://learngitbranching.js.org/" target="_blank" rel="noopener noreferrer">Learn Git Branching</a> - An interactive Git visualization tool to educate and challenge</li><li><a href="http://gitimmersion.com/" target="_blank" rel="noopener noreferrer">Git Immersion</a> - A guided tour that walks through the fundamentals of Git</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="testing-frameworks">Testing frameworks<a class="hash-link" href="#testing-frameworks" title="Direct link to heading"></a></h2><p>Testing frameworks are used to automate the testing process. They enable developers to write tests that can be executed automatically. Learn about popular testing frameworks such as JUnit, TestNG, and Selenium. Familiarize yourself with unit testing, integration testing, and end-to-end testing. This knowledge will enable you to write robust and reliable code.</p><p>Resources to learn Testing Frameworks:</p><ul><li><a href="https://junit.org/junit5/docs/current/user-guide/" target="_blank" rel="noopener noreferrer">JUnit 5 User Guide</a> - The official guide for JUnit 5, a modern testing framework for Java</li><li><a href="https://docs.pytest.org/en/latest/" target="_blank" rel="noopener noreferrer">PyTest Documentation</a> - Comprehensive guide on how to use PyTest, a popular testing framework for Python</li><li><a href="https://jestjs.io/docs/getting-started" target="_blank" rel="noopener noreferrer">Jest Documentation</a> - Learn how to use Jest, a delightful JavaScript Testing Framework with a focus on simplicity</li><li><a href="https://docs.cypress.io/guides/overview/why-cypress" target="_blank" rel="noopener noreferrer">Cypress Documentation</a> - Learn how to use Cypress, a next generation front end testing tool built for the modern web</li><li><a href="https://mochajs.org/" target="_blank" rel="noopener noreferrer">Mocha Documentation</a> - Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="documentation-skills">Documentation Skills<a class="hash-link" href="#documentation-skills" title="Direct link to heading"></a></h2><ul><li>Clear and concise documentation is crucial in software development. This includes not only code comments and README files, but also blog posts and articles that share your knowledge with others. </li></ul><p>Here are some key skills and tools to master:</p><ul><li><p><a href="https://www.markdownguide.org/" target="_blank" rel="noopener noreferrer">Markdown</a> - A lightweight markup language that you can use to write easy-to-read and easy-to-write plain text format, which then converts to structurally valid HTML. It's widely used for README files, documentation, and writing articles on platforms like GitHub and Jekyll blogs.</p></li><li><p><a href="https://mermaid.js.org/" target="_blank" rel="noopener noreferrer">Mermaid.js</a> - A JavaScript library that allows you to create diagrams and flowcharts using text. It integrates well with Markdown, making it great for blog posts that need to explain complex ideas visually.</p></li><li><p><a href="https://microsoft.github.io/language-server-protocol/" target="_blank" rel="noopener noreferrer">Language Server Protocol</a> - A protocol developed by Microsoft that allows code editing tools to provide features like auto-complete, go to definition, find all references and alike without each tool needing to understand each programming language.</p></li><li><p><a href="https://diagrams.mingrammer.com/" target="_blank" rel="noopener noreferrer">Diagram as a Code</a> - A Python library that allows you to create diagrams using code, which is great for prototyping a new system architecture design or explaining system design in your blog posts.</p></li></ul><p>Remember, good documentation skills involve clear communication, good organization, and the ability to explain complex ideas in a simple, understandable way. Practice writing blog posts and articles to improve these skills. You can also contribute to open-source projects by writing documentation for them. Maintain documentation in tools like <a href="http://dendron.so" target="_blank" rel="noopener noreferrer">Dendron</a>, <a href="http://logseq.com" target="_blank" rel="noopener noreferrer">Logseq</a> which is a powerful note-taking system that allows you to organize and navigate your knowledge effectively.</p><p>Once a big knowledge base is built, you can use it to capture coding patterns, solutions to common problems, and snippets of code. Combine it with Markdown files and notebook tools like Jupyter Notebook (NB) to create well-structured and executable documentation. This approach will streamline your workflow and serve as a valuable resource for future reference which can be used with Large Language Models to gain insights.</p><p>Consider all documentation as a code. Refer to my blog post <a href="https://vishalgandhi.in/doc-as-code" target="_blank" rel="noopener noreferrer">Documentation as Code</a> for more information.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="rest-api-knowledge">REST API Knowledge<a class="hash-link" href="#rest-api-knowledge" title="Direct link to heading"></a></h2><p>REST (Representational State Transfer) is an architectural style commonly used for web services. Understanding how REST APIs work and being able to design, build, and consume them is a fundamental skill for software developers. Learn about HTTP methods (GET, POST, PUT, DELETE), URL structure, request/response formats (JSON, XML), authentication, and common best practices for building RESTful APIs. This knowledge will empower you to interact with various web services and build robust and scalable applications.</p><p>In today's software development landscape, REST (Representational State Transfer) APIs have become a fundamental building block. They allow different software systems to communicate and exchange data over the internet. Most interfaces in software organizations are now through REST APIs, and it's nearly impossible to start any product without an "API First" approach.</p><p>Understanding how REST APIs work and being able to design, build, and consume them is a crucial skill for software developers. Learn about HTTP methods (GET, POST, PUT, DELETE), URL structure, request/response formats (JSON, XML), and authentication.</p><p>Here are some resources to get you started:</p><ul><li><a href="https://restfulapi.net/" target="_blank" rel="noopener noreferrer">RESTful API Design</a> - A comprehensive resource for understanding and designing RESTful APIs.</li><li><a href="https://www.youtube.com/watch?v=pKd0Rpw7O48" target="_blank" rel="noopener noreferrer">Building a RESTful API with Node.js</a> - A YouTube tutorial by Academind.</li><li><a href="https://vishalgandhi.in/rest-api-design-rules" target="_blank" rel="noopener noreferrer">My Blog Post on REST API</a> - A deep dive into REST API from my personal experience and understanding.</li></ul><p>In addition to understanding the principles of REST APIs, it's also important to familiarize yourself with some of the popular frameworks that can help you build REST APIs more efficiently:</p><ul><li><a href="https://fastapi.tiangolo.com/" target="_blank" rel="noopener noreferrer">FastAPI</a> - A modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.</li><li><a href="https://gin-gonic.com/" target="_blank" rel="noopener noreferrer">Gin Web Framework</a> - Gin is a web framework written in Go. It features a martini-like API with performance that is up to 40 times faster thanks to httprouter.</li></ul><p>These frameworks provide a set of tools and libraries that simplify the process of building robust and scalable APIs. They handle a lot of the boilerplate code and allow you to focus on the business logic of your application.</p><p>Remember, a well-designed API can be a powerful tool for an organization, enabling it to expose its services to a variety of different clients and create new digital products and services.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="linux-knowledge">Linux knowledge<a class="hash-link" href="#linux-knowledge" title="Direct link to heading"></a></h2><p>Familiarizing yourself with Linux is valuable because many development environments, servers, and cloud services are based on Linux. Gain proficiency in the command line interface (CLI), file navigation, package management, and shell scripting. Understanding Linux will enhance your ability to work with open-source solutions, deploy applications, and troubleshoot issues efficiently.</p><p>To gain a deeper understanding of Linux, consider the following resources:</p><ul><li><p><a href="https://linuxjourney.com/" target="_blank" rel="noopener noreferrer">Linux Journey</a> - A free, self-guided tour to help you learn Linux.</p></li><li><p><a href="https://www.amazon.com/Linux-Command-Line-Complete-Introduction/dp/1593273894" target="_blank" rel="noopener noreferrer">The Linux Command Line: A Complete Introduction</a> by William E. Shotts Jr. - This book is a comprehensive guide to using the command line to perform various tasks in Linux.</p></li><li><p><a href="https://www.amazon.com/How-Linux-Works-3rd-Superuser/dp/1718500408" target="_blank" rel="noopener noreferrer">How Linux Works, 3rd Edition: What Every Superuser Should Know</a> by Brian Ward - This book offers a comprehensive, updated guide to understanding how Linux operates.</p></li><li><p>Shell scripting is a powerful tool that can automate tasks and manage system configurations. Here are some of the best books to learn shell scripting:</p></li><li><p><a href="https://www.amazon.com/Learning-bash-Shell-Programming-Third/dp/0596009658" target="_blank" rel="noopener noreferrer">Learning the bash Shell: Unix Shell Programming</a> by Cameron Newham - This book is a complete guide to bash, the default shell for Linux.</p></li><li><p><a href="https://www.amazon.com/Shell-Scripting-Expert-Recipes-Linux/dp/1118024486" target="_blank" rel="noopener noreferrer">Shell Scripting: Expert Recipes for Linux, Bash, and More</a> by Steve Parker - A compendium of shell scripting recipes that can immediately be used, adjusted, and applied.</p></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="contribute-to-open-source-solutions">Contribute to Open Source Solutions<a class="hash-link" href="#contribute-to-open-source-solutions" title="Direct link to heading"></a></h2><p>Embrace the open-source community as a software developer. Contributing to open-source projects not only allows you to collaborate with experienced developers but also helps you refine your coding skills. By studying open-source projects, you can learn about software architecture, coding standards, best practices, and gain exposure to different programming languages and frameworks. Explore popular open-source repositories such as GitHub and start contributing to projects aligned with your interests.</p><p>Here are some resources to get you started:</p><ul><li><a href="https://www.firsttimersonly.com/" target="_blank" rel="noopener noreferrer">First Timers Only</a> - A site dedicated to helping newcomers get started with contributing to open-source projects.</li><li><a href="https://github.com/topics/good-first-issue" target="_blank" rel="noopener noreferrer">GitHub "Good First Issue" Label</a> - GitHub's "Good First Issue" label is a great way to find projects that are beginner-friendly. These issues are specifically marked by project maintainers as good entry points for new contributors.</li><li><a href="https://opensource.guide/" target="_blank" rel="noopener noreferrer">Open Source Guide</a> - This guide provides resources for contributing to open source, from finding a project to making a contribution.</li><li><a href="https://up-for-grabs.net/#/" target="_blank" rel="noopener noreferrer">Up For Grabs</a> - This site aggregates (groups together) projects that have tasks specifically for new contributors.</li></ul><p>Remember, contributing to open source is not just about coding. You can contribute in many ways, including documentation, design, teaching, and more.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="learn-standard-way-of-writing-solutions">Learn Standard Way of Writing Solutions<a class="hash-link" href="#learn-standard-way-of-writing-solutions" title="Direct link to heading"></a></h2><p>Developers often encounter challenges in writing clean, maintainable, and well-documented code. Embrace standard practices and methodologies to overcome these challenges.</p><p>For example, when building command-line interfaces (CLI), consider using libraries like docopt to create command-line interfaces with ease. </p><p>Resources for CLI:</p><ul><li><a href="http://docopt.org/" target="_blank" rel="noopener noreferrer">docopt</a> - A command-line interface description language that will make you smile.</li><li><a href="https://clig.dev/" target="_blank" rel="noopener noreferrer">Command Line Interface Guidelines</a> - A guide to help you write command-line programs that respect the conventions of the Unix philosophy.</li></ul><p>When developing REST APIs, adhere to established standards such as the Richardson Maturity Model or OpenAPI specifications to ensure consistency and interoperability. </p><p>Resources for REST APIs:</p><ul><li><a href="https://martinfowler.com/articles/richardsonMaturityModel.html" target="_blank" rel="noopener noreferrer">Richardson Maturity Model</a> - A model (developed by Leonard Richardson) that breaks down the principal elements of a REST approach into three steps.</li><li><a href="https://swagger.io/specification/" target="_blank" rel="noopener noreferrer">OpenAPI Specification</a> - A standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection.</li></ul><p>These practices will make your code more robust, readable, and easier to maintain.</p><p>Resources for Clean Code:</p><ul><li><a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882" target="_blank" rel="noopener noreferrer">Clean Code: A Handbook of Agile Software Craftsmanship</a> by Robert C. Martin - A book that describes the principles, patterns, and practices of writing clean code.</li><li><a href="https://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672" target="_blank" rel="noopener noreferrer">Refactoring: Improving the Design of Existing Code</a> by Martin Fowler - A book about how to clean up code to minimize the chance of introducing bugs.</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a class="hash-link" href="#conclusion" title="Direct link to heading"></a></h2><p>Embarking on a career as a software developer requires continuous learning and adaptation. By focusing on the key skills, tools, and technologies mentioned in this article, you will be able to establish a solid foundation and thrive in this field. Remember, it's not about how much you know but how well you can apply what you know. So, keep learning and practicing!</p>]]></content:encoded>
<category>career</category>
<category>fundamentals</category>
<category>essential-skills</category>
</item>
<item>
<title><![CDATA[My favorite Open Source Projects in 2022]]></title>
<link>https://ivishalgandhi.github.io/fav-open-source-repo</link>
<guid>fav-open-source-repo</guid>
<pubDate>Fri, 30 Dec 2022 00:00:00 GMT</pubDate>
<description><![CDATA[Open Source is a great way to learn and contribute to the community. With a nearly endless array of open source projects available to consume and contribute to these days, Need some inspiration? Whether you’re new to the world of open source, are gearing up for Open Source in the new year, or just want to see what other folks are excited about, check out a few of my favorite open source projects i discovered during 2022.]]></description>
<content:encoded><![CDATA[<p>Open Source is a great way to learn and contribute to the community. With a nearly endless array of open source projects available to consume and contribute to these days, Need some inspiration? Whether you’re new to the world of open source, are gearing up for Open Source in the new year, or just want to see what other folks are excited about, check out a few of my favorite open source projects i discovered during 2022. </p><table><thead><tr><th>Category</th><th>Repository</th><th>Site URL</th><th>Description</th></tr></thead><tbody><tr><td><strong>Browser</strong></td><td><a href="https://gitlab.com/librewolf-community" target="_blank" rel="noopener noreferrer"><strong>LibreWolf</strong></a></td><td><a href="https://librewolf.net/" target="_blank" rel="noopener noreferrer">https://librewolf.net/</a></td><td>LibreWolf is a privacy-oriented web browser based on Firefox</td></tr><tr><td><strong>Browser</strong></td><td><a href="https://github.com/brave/brave-browser" target="_blank" rel="noopener noreferrer"><strong>Brave</strong></a></td><td><a href="https://brave.com/" target="_blank" rel="noopener noreferrer">https://brave.com/</a></td><td>Brave is a privacy-oriented web browser based on Chromium</td></tr><tr><td><strong>Task Runner</strong></td><td><a href="https://github.com/go-task/task" target="_blank" rel="noopener noreferrer"><strong>go-task</strong></a></td><td><a href="https://taskfile.dev/" target="_blank" rel="noopener noreferrer">https://taskfile.dev/</a></td><td>Task is a task runner / simpler Make alternative written in Go</td></tr><tr><td><strong>Data Analysis</strong></td><td><a href="https://github.com/pandas-dev/pandas" target="_blank" rel="noopener noreferrer"><strong>Pandas</strong></a></td><td><a href="https://pandas.pydata.org/" target="_blank" rel="noopener noreferrer">https://pandas.pydata.org/</a></td><td>Pandas is a data analysis library for Python</td></tr><tr><td><strong>Object Storage</strong></td><td><a href="https://github.com/minio/minio" target="_blank" rel="noopener noreferrer"><strong>Minio</strong></a></td><td><a href="https://min.io/" target="_blank" rel="noopener noreferrer">https://min.io/</a></td><td>Minio is an object storage server that is compatible with Amazon S3</td></tr><tr><td><strong>Terminal</strong></td><td><a href="https://github.com/Eugeny/tabby" target="_blank" rel="noopener noreferrer"><strong>Tabby</strong></a></td><td><a href="https://tabby.sh/" target="_blank" rel="noopener noreferrer">https://tabby.sh/</a></td><td>A Terminal for the modern age</td></tr><tr><td><strong>Terminal</strong></td><td><a href="https://github.com/tmux/tmux" target="_blank" rel="noopener noreferrer"><strong>Tmux</strong></a></td><td><a href="https://github.com/tmux/tmux" target="_blank" rel="noopener noreferrer">https://github.com/tmux/tmux</a></td><td>tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.</td></tr><tr><td><strong>Terminal</strong></td><td><a href="https://github.com/tmuxinator/tmuxinator" target="_blank" rel="noopener noreferrer"><strong>Tmuxinator</strong></a></td><td><a href="https://github.com/tmuxinator/tmuxinator" target="_blank" rel="noopener noreferrer">https://github.com/tmuxinator/tmuxinator</a></td><td>Tmuxinator is a tool for managing complex tmux sessions easily.</td></tr><tr><td><strong>Code Editor</strong></td><td><a href="http://https://github.com/microsoft/vscode" target="_blank" rel="noopener noreferrer"><strong>Visual Studio Code</strong></a></td><td><a href="https://code.visualstudio.com/" target="_blank" rel="noopener noreferrer">https://code.visualstudio.com/</a></td><td>Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Built on top of <a href="https://github.com/electron/electron" target="_blank" rel="noopener noreferrer">Electron</a></td></tr><tr><td><strong>Code Editor</strong></td><td><a href="https://github.com/neovim/neovim" target="_blank" rel="noopener noreferrer"><strong>neovim</strong></a></td><td><a href="https://neovim.io/" target="_blank" rel="noopener noreferrer">https://neovim.io/</a></td><td>Neovim is a text editor based on Vim. Last few months, i have been using <code>neovim</code> more often compared to <code>Visual Studio Code</code></td></tr><tr><td><strong>Productivity - Note Taking</strong></td><td><a href="https://github.com/dendronhq/dendron" target="_blank" rel="noopener noreferrer"><strong>Dendron</strong></a></td><td><a href="https://dendron.so/" target="_blank" rel="noopener noreferrer">https://dendron.so/</a></td><td>Dendron is my goto note taking tool. Its available as a plugin for VSCode and allows hirearchy and graph based note taking. Awesome solution to mantain a <code>second-brain</code></td></tr><tr><td><strong>Productivity - Bookmark Manager</strong></td><td><a href="https://github.com/jarun/buku" target="_blank" rel="noopener noreferrer"><strong>Buku</strong></a></td><td><a href="https://github.com/jarun/buku#quickstart" target="_blank" rel="noopener noreferrer">https://github.com/jarun/buku#quickstart</a></td><td>Buku is a command-line bookmark manager.</td></tr><tr><td><strong>Private Network VPN</strong></td><td><a href="https://github.com/tailscale/tailscale" target="_blank" rel="noopener noreferrer"><strong>Tailscale</strong></a></td><td><a href="https://tailscale.com/" target="_blank" rel="noopener noreferrer">https://tailscale.com/</a></td><td>Tailscale is a private network VPN. Helps me create a private network for all my home lab machines and devices</td></tr><tr><td><strong>Tunnelling</strong></td><td><a href="https://github.com/inconshreveable/ngrok" target="_blank" rel="noopener noreferrer"><strong>ngrok</strong></a></td><td><a href="https://ngrok.com/" target="_blank" rel="noopener noreferrer">https://ngrok.com/</a></td><td>ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels.</td></tr><tr><td><strong>Tunnelling</strong></td><td><a href="https://github.com/localtunnel/localtunnel" target="_blank" rel="noopener noreferrer"><strong>localtunnel</strong></a></td><td><a href="https://localtunnel.github.io/www/" target="_blank" rel="noopener noreferrer">https://localtunnel.github.io/www/</a></td><td>localtunnel exposes your localhost to the world for easy testing and sharing! No need to mess with DNS or deploy just to have others test out your changes.</td></tr><tr><td><strong>Containers</strong></td><td><a href="https://github.com/containers/podman" target="_blank" rel="noopener noreferrer"><strong>Podman</strong></a></td><td><a href="https://podman.io/" target="_blank" rel="noopener noreferrer">https://podman.io/</a></td><td>Podman is a daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative (OCI) Containers and Container Images.</td></tr><tr><td><strong>Container Scheduling and Management</strong></td><td><a href="https://github.com/kubernetes/kubernetes" target="_blank" rel="noopener noreferrer"><strong>Kubernetes</strong></a></td><td><a href="https://kubernetes.io/" target="_blank" rel="noopener noreferrer">https://kubernetes.io/</a></td><td>Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.</td></tr><tr><td><strong>Static Site Generator</strong></td><td><a href="https://github.com/facebook/docusaurus" target="_blank" rel="noopener noreferrer"><strong>Docusaurus</strong></a></td><td><a href="https://docusaurus.io/" target="_blank" rel="noopener noreferrer">https://docusaurus.io/</a></td><td>Docusaurus is a static site generator written in JavaScript. Build optimized websites quickly, focus on your content.</td></tr><tr><td><strong>Static Site Generator</strong></td><td><a href="https://github.com/gohugoio/hugo" target="_blank" rel="noopener noreferrer"><strong>Hugo</strong></a></td><td><a href="https://gohugo.io/" target="_blank" rel="noopener noreferrer">https://gohugo.io/</a></td><td>Hugo is a static site generator written in <code>Go</code>.</td></tr><tr><td><strong>Diagram as a Code</strong></td><td><a href="https://github.com/mermaid-js/mermaid" target="_blank" rel="noopener noreferrer"><strong>Mermaid</strong></a></td><td><a href="https://mermaid.js.org/" target="_blank" rel="noopener noreferrer">https://mermaid.js.org/</a></td><td>Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown</td></tr><tr><td><strong>Diagram as a Code</strong></td><td><a href="https://github.com/plantuml/plantuml" target="_blank" rel="noopener noreferrer"><strong>PlantUML</strong></a></td><td><a href="https://plantuml.com/" target="_blank" rel="noopener noreferrer">https://plantuml.com/</a></td><td>Generate diagrams from textual description</td></tr><tr><td><strong>Diagram as a Code</strong></td><td><a href="https://github.com/jgraph/drawio" target="_blank" rel="noopener noreferrer"><strong>Draw.io</strong></a></td><td><a href="https://app.diagrams.net/" target="_blank" rel="noopener noreferrer">https://app.diagrams.net/</a></td><td>draw.io, this project, is a configurable diagramming/whiteboarding visualization application. draw.io is jointly owned and developed by JGraph Ltd and draw.io AG.</td></tr><tr><td><strong>Diagram as a Code</strong></td><td><a href="https://github.com/excalidraw/excalidraw" target="_blank" rel="noopener noreferrer"><strong>Excalidraw</strong></a></td><td><a href="https://excalidraw.com/" target="_blank" rel="noopener noreferrer">https://excalidraw.com/</a></td><td>Excalidraw is a free software that offers a whiteboard tool that lets you easily sketch diagrams with a hand-drawn feel. Another features are the collaborative mode, and the ability to export the diagrams to PNG or SVG formats, and to save them locally in a JSON format</td></tr><tr><td><strong>Diagram as a Code</strong></td><td><a href="https://github.com/mingrammer/diagrams" target="_blank" rel="noopener noreferrer"><strong>mingrammer</strong></a></td><td><a href="https://diagrams.mingrammer.com/" target="_blank" rel="noopener noreferrer">https://diagrams.mingrammer.com/</a></td><td>Diagrams as code for prototyping cloud system architecture.</td></tr><tr><td><strong>Web Framework</strong></td><td><a href="https://github.com/gin-gonic/gin" target="_blank" rel="noopener noreferrer"><strong>Gin</strong></a></td><td><a href="https://gin-gonic.com/" target="_blank" rel="noopener noreferrer">https://gin-gonic.com/</a></td><td>Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API, but with performance up to 40 times faster than Martini. If you need smashing performance, get yourself some Gin.</td></tr><tr><td><strong>Web Framework</strong></td><td><a href="https://github.com/tiangolo/fastapi" target="_blank" rel="noopener noreferrer"><strong>FAST API</strong></a></td><td><a href="https://fastapi.tiangolo.com/" target="_blank" rel="noopener noreferrer">https://fastapi.tiangolo.com/</a></td><td>FastAPI is a Web framework for developing RESTful APIs in Python. FastAPI is based on Pydantic and type hints to validate, serialize, and deserialize data, and automatically auto-generate OpenAPI documents. It fully supports asynchronous programming and can run with Gunicorn and ASGI servers for production such as Uvicorn and Hypercorn. To improve developer-friendliness, editor support was considered since the earliest days of the project.</td></tr><tr><td><strong>Web Framework</strong></td><td><a href="https://github.com/withastro/astro" target="_blank" rel="noopener noreferrer"><strong>Astro</strong></a></td><td><a href="https://astro.build/" target="_blank" rel="noopener noreferrer">https://astro.build/</a></td><td>Astro works with your favorite content sources. Pull content from the filesystem or fetch it remotely from your favorite CMS, database, or API. Astro supports both static output (SSG) and live server output (SSR) that can render your content on-demand.</td></tr><tr><td><strong>Search Engine</strong></td><td><a href="https://github.com/typesense/typesense" target="_blank" rel="noopener noreferrer"><strong>Typesense</strong></a></td><td><a href="https://typesense.org/" target="_blank" rel="noopener noreferrer">https://typesense.org/</a></td><td>Typesense is a modern, privacy-friendly, open source search engine built from the ground up using cutting-edge search algorithms, that take advantage of the latest advances in hardware capabilities.</td></tr><tr><td><strong>Nocode Platform</strong></td><td><a href="https://github.com/nocodb/nocodb" target="_blank" rel="noopener noreferrer"><strong>NOCODB</strong></a></td><td><a href="https://nocodb.com/" target="_blank" rel="noopener noreferrer">https://nocodb.com/</a></td><td>NocoDB is an open-source low-code platform for building and managing internal tools and turning your SQL Databases into a smart spreadsheet. It is a self-hosted alternative to Airtable, Notion, and Airtable.</td></tr><tr><td><strong>Distributed Database</strong></td><td><a href="https://github.com/rqlite/rqlite" target="_blank" rel="noopener noreferrer"><strong>rqlite</strong></a></td><td><a href="https://rqlite.com/" target="_blank" rel="noopener noreferrer">https://rqlite.com/</a></td><td>rqlite is an easy-to-use, lightweight, distributed relational database, which uses SQLite as its storage engine. rqlite is simple to deploy, operating it is very straightforward, and its clustering capabilities provide you with fault-tolerance and high-availability.</td></tr><tr><td><strong>Multi-modal Database</strong></td><td><a href="https://github.com/surrealdb/surrealdb" target="_blank" rel="noopener noreferrer"><strong>SurrealDB</strong></a></td><td><a href="https://surrealdb.com/" target="_blank" rel="noopener noreferrer">https://surrealdb.com/</a></td><td>SurrealDB combines the database layer, the querying layer, and the API and authentication layer into one platform. Advanced table-based and row-based customisable access permissions allow for granular data access patterns for different types of users. There's no need for custom backend code and security rules with complicated database development.</td></tr><tr><td><strong>Multi-modal Database</strong></td><td><a href="https://github.com/arangodb/arangodb" target="_blank" rel="noopener noreferrer"><strong>ArangoDB</strong></a></td><td><a href="https://www.arangodb.com/" target="_blank" rel="noopener noreferrer">https://www.arangodb.com/</a></td><td>ArangoDB is a free and open-source native graph database system developed by ArangoDB Inc. ArangoDB is a multi-model database system since it supports three data models with one database core and a unified query language AQL. AQL is mainly a declarative language and allows the combination of different data access patterns in a single query.</td></tr><tr><td><strong>Git for Data</strong></td><td><a href="https://github.com/dolthub/dolt" target="_blank" rel="noopener noreferrer"><strong>Dolt</strong></a></td><td><a href="https://dolthub.com/" target="_blank" rel="noopener noreferrer">https://dolthub.com/</a></td><td>Dolt is a SQL database that you can fork, clone, branch, merge, push and pull just like a Git repository. Connect to Dolt just like any MySQL database to run queries or update the data using SQL commands. Use the command line interface to import CSV files, commit your changes, push them to a remote, or merge your teammate's changes.</td></tr><tr><td><strong>Personal Finance</strong></td><td><a href="https://github.com/firefly-iii/firefly-iii" target="_blank" rel="noopener noreferrer"><strong>Firefly III</strong></a></td><td><a href="https://firefly-iii.org/" target="_blank" rel="noopener noreferrer">https://firefly-iii.org/</a></td><td>"Firefly III" is a (self-hosted) manager for your personal finances. It can help you keep track of your expenses and income, so you can spend less and save more. Firefly III supports the use of budgets, categories and tags. Using a bunch of external tools, you can import data. It also has many neat financial reports available.</td></tr><tr><td><strong>Monitoring and TSDB</strong></td><td><a href="https://github.com/prometheus/prometheus" target="_blank" rel="noopener noreferrer">Prometheus</a></td><td><a href="https://prometheus.io/" target="_blank" rel="noopener noreferrer">https://prometheus.io/</a></td><td>Prometheus is a systems and service monitoring system. It collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some condition is observed to be true.</td></tr></tbody></table>]]></content:encoded>
<category>open-source</category>
<category>2022</category>
<category>favourite-repo</category>
</item>
<item>
<title><![CDATA[Documentation as a code]]></title>
<link>https://ivishalgandhi.github.io/doc-as-code</link>
<guid>doc-as-code</guid>
<pubDate>Sat, 22 Oct 2022 00:00:00 GMT</pubDate>
<description><![CDATA[Documentation is the most critical activity of any product development. The engineer and user experience improve when there is up-to-date Documentation. Most often, in organizations and products, Documentation is an afterthought, and this is not a good practice. If we want more engineers to contribute to the product, Documentation should be considered as code and part of the product development. Engineers should be encouraged to write Documentation before writing the source code.]]></description>
<content:encoded><![CDATA[<p>Documentation is the most critical activity of any product development. The engineer and user experience improve when there is up-to-date Documentation. Most often, in organizations and products, Documentation is an afterthought, and this is not a good practice. If we want more engineers to contribute to the product, Documentation should be considered as code and part of the product development. Engineers should be encouraged to write Documentation before writing the source code.</p><p> In many organizations, Documentation is everywhere, but it can be challenging to find. It is often written in various formats, and it is sometimes unclear who is responsible for it. It also needs to be clarified how to contribute to it. Confidence in Documentation could be higher if engineers spent more time writing; there is more incentive to write, and setting up a culture to write docs as part of engineering workflow contributes to Engineer Productivity which is a crucial metric for any organization.</p><p>The product engineering teams must identify workflows to integrate Documentation into the existing process to solve the challenges listed below.</p><ul><li>The Documentation is not part of the codebase</li><li>The Documentation is not part of the CI/CD pipeline</li><li>The method of writing Documentation is not integrated into the engineering workflow</li><li>The Documentation is not reviewed and tested</li><li>The Documentation is written in a separate tool and is not version controlled</li></ul><p>Documentation will never be part of engineering culture unless integrated into the codebase and workflow.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="what-is-docs-as-code">What is Docs as Code?<a class="hash-link" href="#what-is-docs-as-code" title="Direct link to heading"></a></h2><ul><li>Store the source file version of Documentation in a version control system like Git</li><li>Automatically build doc artifacts </li><li>Publish artifacts without human intervention</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="why-docs-as-code">Why Docs as Code?<a class="hash-link" href="#why-docs-as-code" title="Direct link to heading"></a></h2><ul><li><p>The Documentation evolves with the code. The flowchart, System Architecture and other diagrams will be up-to-date as the code changes</p></li><li><p>Long release cycles may result in logic or flowchart being forgotten or outdated</p></li><li><p>Consistency is critical for the adoption of Docs as a code. Teams can collaborate on the Documentation and can ensure that the Documentation is consistent across the product</p></li><li><p>Collaboration across product teams is the critical piece of why Documentation should be considered a code</p></li><li><p>Documentation can be reviewed and approved by the team members</p></li><li><p>Centralized Internal Documentation framework and familiar structured Documentation for all the products </p></li><li><p>Track Documentation mistakes as bugs</p></li><li><p>Documentation can be versioned, tested, and tracked</p></li><li><p>Manage the complexity around the documentation process</p></li><li><p>Visualize the Documentation in the form of diagrams, flowcharts, and images</p></li><li><p>Engineer can use other tools to model dependencies. For example, the Product team can use Mermaid to model the flowchart, system architecture, class diagram, and sequence diagrams</p></li><li><p>Avoid effort to redo the Documentation when a team member leaves the organization. </p></li><li><p>The product team can automate Workflows can be automated to generate the Documentation</p></li><li><p>Makes Documentation standout with <a href="https://www.markdownguide.org/" target="_blank" rel="noopener noreferrer">Markdown</a></p><div class="theme-admonition theme-admonition-info alert alert--info admonition_LlT9"><div class="admonitionHeading_tbUL"><span class="admonitionIcon_kALy"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg></span>info</div><div class="admonitionContent_S0QG"><p>Markdown is a simple, lightweight markup language that is easy to learn and use for plain text formatting and conversion to HTML and many other formats using a tool. Markdown is often used to format readme files, write messages in online discussion forums, and create rich text using a plain text editor.</p></div></div></li></ul><div></div><h2 class="anchor anchorWithStickyNavbar_LWe7" id="types-of-documentation">Types of Documentation<a class="hash-link" href="#types-of-documentation" title="Direct link to heading"></a></h2><p>The most common types of Documentation for every product are:</p><ul><li><p>Long-form </p><ul><li>FAQs, User Guides, Tutorials, How-to Guides, etc.</li></ul></li><li><p>Functional </p><ul><li>REST API Documentation, SDK Documentation, etc.</li></ul></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="how-to-do-docs-as-a-code">How to do Docs as a Code?<a class="hash-link" href="#how-to-do-docs-as-a-code" title="Direct link to heading"></a></h2><ul><li>Version your Documentation. Just as you version your code, you should version your Documentation. Versioning allows tracking changes and rollbacks to previous versions if necessary.</li><li>Integrate Documentation with CI/CD pipeline. CI/CD Integration will allow you to automate the process of generating Documentation and publishing it to a central location</li><li>Start with Proof of Concept and extend to all the products gradually </li><li>Choose a static site generator (Documentation Tool) that can be integrated with the CI/CD pipeline</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="docs-as-code-tools">Docs As Code Tools<a class="hash-link" href="#docs-as-code-tools" title="Direct link to heading"></a></h2><ul><li><p>Static Site Generators
They are used for Long form documentation. Allows integration of diagrams, flowcharts, images, etc.</p><ul><li><a href="http://docusaurus.io" target="_blank" rel="noopener noreferrer">Docusaurus</a>, <a href="https://gohugo.io" target="_blank" rel="noopener noreferrer">Hugo</a>, <a href="https://www.gatsbyjs.com" target="_blank" rel="noopener noreferrer">Gatsby</a>, <a href="https://jekyllrb.com" target="_blank" rel="noopener noreferrer">Jekyll</a>, <a href="https://www.mkdocs.org" target="_blank" rel="noopener noreferrer">MkDocs</a> etc.</li></ul></li><li><p>Diagram as a code</p><p>Allows creating diagrams, flowcharts, etc., in a code format. Think of documenting and visualizing a complex system architecture in a code format.</p><ul><li><a href="https://mermaid-js.github.io/mermaid/#/" target="_blank" rel="noopener noreferrer">Mermaid</a>, <a href="https://plantuml.com/" target="_blank" rel="noopener noreferrer">PlantUML</a>, <a href="https://graphviz.org/" target="_blank" rel="noopener noreferrer">Graphviz</a>, <a href="https://www.draw.io/" target="_blank" rel="noopener noreferrer">Draw.io</a>, <a href="https://diagrams.mingrammer.com" target="_blank" rel="noopener noreferrer">mingrammer/Diagrams</a></li></ul></li><li><p>Source code-based document generators </p><ul><li><a href="https://www.sphinx-doc.org/en/master/" target="_blank" rel="noopener noreferrer">Sphinx</a></li></ul></li><li><p>System documentation generators</p><ul><li><a href="https://github.com/rtomayko/ronn" target="_blank" rel="noopener noreferrer">ronn</a></li></ul></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="final-thoughts">Final Thoughts<a class="hash-link" href="#final-thoughts" title="Direct link to heading"></a></h2><p>Everything(Infrastructure, Monitoring, Code, Containers, Documentation) as a code is already a reality. For some organizations, the shift to treating Documentation as a code is a complex overhaul of expectations, attitudes, processes, and toolsets. Once implemented, it will vastly improve the engineer and user experience. For open-source projects, it is even more essential to have good Documentation. It is a great way to attract new contributors and users. </p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="references">References<a class="hash-link" href="#references" title="Direct link to heading"></a></h2><ul><li><a href="https://www.writethedocs.org/guide/doc-ops/#what-is-docops-anyway" target="_blank" rel="noopener noreferrer">DocOps</a></li></ul>]]></content:encoded>
<category>docops</category>
<category>doc-as-code</category>
</item>
<item>
<title><![CDATA[Understanding REST API Design Rules]]></title>
<link>https://ivishalgandhi.github.io/rest-api-design-rules</link>
<guid>rest-api-design-rules</guid>
<pubDate>Sun, 02 Oct 2022 00:00:00 GMT</pubDate>
<description><![CDATA[Introduction to REST API]]></description>
<content:encoded><![CDATA[<h2 class="anchor anchorWithStickyNavbar_LWe7" id="introduction-to-rest-api">Introduction to REST API<a class="hash-link" href="#introduction-to-rest-api" title="Direct link to heading"></a></h2><p>REST (Representational State Transfer) is an architectural style for building distributed systems. A Web API conforms to the REST architectural style, called RESTful Web API. </p><p>REST APIs are stateless, client-server, cacheable, layered systems designed around resources. The set of resources is known as the REST API's <em>resource model</em></p><div></div><p>REST APIs are one of the most common and fundamental ways to expose data and functionality as web services. REST APIs use HTTP requests to GET, PUT, POST, and DELETE data. </p><p>An adequately designed REST API should be easy to understand, use, and evolve over time. It will help clients and browser apps consume the API more efficiently. </p><p>Before designing and developing a REST API, we need to seek answers to the following questions:</p><ul><li>What are URI Paths? Structure of URI Path segments? </li><li>When to use plural nouns or verbs for URI Path segments?</li><li>What is the HTTP response status code, and how to use it in a specific scenario? </li><li>How to map non-CRUD operations to HTTP methods? </li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="understanding-uniform-resource-identifier-uri">Understanding Uniform Resource Identifier (URI)<a class="hash-link" href="#understanding-uniform-resource-identifier-uri" title="Direct link to heading"></a></h2><p>REST APIs use Uniform Resource Identifiers (URIs) to identify resources. A resource is any information that can be named. Resources are separated by forward slashes (/). A good URI should be short, easy to remember, and should give the user an idea about the resource.</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="uri-format">URI Format<a class="hash-link" href="#uri-format" title="Direct link to heading"></a></h3><p>The URI format is as follows:</p><p>URI = scheme "://" host <!-- -->[ ":" port ][ "/" path ]<!-- --> <!-- -->[ "?" query ][ "#" fragment ]</p><div class="language-http codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-http codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">http://<domain-name>/<resource-name>/<resource-id></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="uri-resource-model">URI Resource Model<a class="hash-link" href="#uri-resource-model" title="Direct link to heading"></a></h3><table><thead><tr><th>Header</th><th>Description</th></tr></thead><tbody><tr><td>Document</td><td>A document resource is similar to database record or instance of an object. It is a single resource that can be retrieved, created, updated, or deleted. <br> For example, information about a blog author is a document resource. <br> <code>http://api.blog.com/authors/vishal-gandhi</code></td></tr><tr><td>Collection</td><td>A collection resource is a server-managed directory of resources. <br> For example, a list of blog authors is a collection resource. <br> <code>http://api.blog.com/authors</code></td></tr><tr><td>Store</td><td>A store is a repository which is managed by client. Using store resource client can create, update, delete and retrieve documents. <br> <code>http://api.blog.com/store/authors/vishal-gandhi</code></td></tr><tr><td>Controller</td><td>A controller resource models a procedure concept. It is a resource that represents a procedure that can be invoked. A controller resource is a collection resource that supports the POST method. The POST method is used to invoke the controller resource. The controller resource can be used to model a procedure that can be invoked. For example, the following URI models a controller resource that represents a procedure that can be invoked to send an email: <br> <code>POST /api.blog.com/email/email/send</code> <br> <code>{Collection}/{Store}/{Document}/{Controller}</code></td></tr></tbody></table><h2 class="anchor anchorWithStickyNavbar_LWe7" id="rest-api-design-rules">REST API Design Rules<a class="hash-link" href="#rest-api-design-rules" title="Direct link to heading"></a></h2><h3 class="anchor anchorWithStickyNavbar_LWe7" id="uri">URI<a class="hash-link" href="#uri" title="Direct link to heading"></a></h3><ul><li><strong>Rule : Forward Slash (/) is used to separate resources in the URI and indicate a hierarchical relationship</strong></li></ul><p>A trailing forward slash (/) is not required as the last character of a URI. Many web servers automatically redirect requests with a trailing forward slash to the same URI without the trailing forward slash.</p><ul><li><p><strong>Rule : Use plural nouns for URI Path segments that represent collections or resources</strong></p></li><li><p><strong>Rule : Use HTTP Methods to Perform Operations on Resources</strong></p></li></ul><p>HTTP methods are used to perform operations on resources. The following table lists the HTTP methods and their corresponding operations:</p><table><thead><tr><th>HTTP Method</th><th>Operation</th></tr></thead><tbody><tr><td>GET</td><td>Retrieve a resource</td></tr><tr><td>POST</td><td>Create a resource</td></tr><tr><td>PUT</td><td>Update a resource</td></tr><tr><td>DELETE</td><td>Delete a resource</td></tr><tr><td>PATCH</td><td>Update a resource with Partial data</td></tr></tbody></table><div class="language-JS codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-JS codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">const express = require('express');</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">const bodyParser = require('body-parser');</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">const app = express();</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">const port = 3000;</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">app.use(bodyParser.json());</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">app.get('/authors', (req, res) => {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">res.send('Authors List'); </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">//get author list from Sql lite backend </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">res.json(authors);</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">});</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">app.post('/authors', (req, res) => {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> res.send('Add Author');</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> //add author to Sql lite backend</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> res.json(author);</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">});</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">//update an author</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">app.put('/authors/:id', (req, res) => {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> res.send('Update Author');</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> res.json(author);</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">});</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">//delete an author</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">app.delete('/authors/:id', (req, res) => {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> res.send('Delete Author');</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> res.json(author);</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">});</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">app.patch('/authors/:id', (req, res) => {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> res.send('Update Author Email');</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> res.json(author);</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">}); </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">app.listen(port, () => {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> console.log(`Blog Example app listening at http://localhost:${port}`);</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">});</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li><strong>Rule : Hyphen (-) is used to separate words in URI Path</strong></li></ul><p>Hyphens (-) are used to separate words in URI path. For example, the URI path for a resource named <em>user-profile</em> is <em>/user-profile</em>.</p><ul><li><strong>Rule : Underscore (_) is not used in URI</strong></li></ul><p>Underscores (_) are not used in URI path due to text editors and browsers depending on the font hide the underscore by underlining the text.</p><ul><li><strong>Rule : File Extensions are not used in URI</strong></li></ul><p>A REST API should not use file extensions in the URI. For example, the URI path for a resource named <em>user-profile</em> is <em>/user-profile</em> and not <em>/user-profile.json</em>.</p><ul><li><strong>Rule : If API Provides a developer portal then it should be accessible via a consistent subdomain</strong></li></ul><p>If an API provides a developer portal, then the developer portal should be accessible via a consistent subdomain. For example, the developer portal for the weather API is accessible via <em>developer.blog.api.com</em>.</p><ul><li><strong>Rule : Lowercase letters are preferred in URI</strong></li></ul><p>Lowercase letters are preferred in URI. For example, the URI path for a resource named <em>user-profile</em> is <em>/user-profile</em> and not <em>/User-Profile</em>.</p><ul><li><strong>Rule: Use a Verb or verb phrase for Controller Names</strong></li></ul><div class="language-http codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-http codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">POST /api.blog.com/email/email/send</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li><strong>Rule: CRUD function names should not be used in the URI</strong></li></ul><p>The following table lists the CRUD functions and their corresponding HTTP methods:</p><table><thead><tr><th>CRUD Function</th><th>HTTP Method</th></tr></thead><tbody><tr><td>Create</td><td>POST</td></tr><tr><td>Read</td><td>GET</td></tr><tr><td>Update</td><td>PUT</td></tr><tr><td>Delete</td><td>DELETE</td></tr></tbody></table><p>e.g. Preferred API Interface</p><div class="language-http codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-http codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">PUT /api.blog.com/authors/vishal-gandhi</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>Anti pattern </p><div class="language-http codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-http codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">DELETE /deleteusers/abc/</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li><strong>Rule: New URIs should be introduced new concepts</strong></li></ul><p>A REST API should introduce new URIs for new concepts. For example, the following table lists the URIs for a user resource:</p><table><thead><tr><th>URI</th><th>Description</th></tr></thead><tbody><tr><td>/authors</td><td>Returns a list of authors</td></tr><tr><td>/authors/vishalgandhi</td><td>Returns the author details</td></tr><tr><td>/authors/vishalgandhi/books</td><td>Returns a list of articles written by the author</td></tr></tbody></table><ul><li><p><strong>Rule: JSON should be well formed and supported for resource representation</strong></p></li><li><p><strong>Rule: Add Versioning at the start of the URI</strong></p></li></ul><div class="language-http codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-http codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">http://api.blog.com/v1/authors/vishal-gandhi</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="http-methods">HTTP Methods<a class="hash-link" href="#http-methods" title="Direct link to heading"></a></h3><ul><li><p><strong>Rule: GET must be used to retrieve representation of a resource</strong></p></li><li><p><strong>Rule: Head must be used to retrieve metadata of a resource and response headers</strong></p></li><li><p><strong>Rule: PUT must be used to both insert and update a resource</strong></p></li><li><p><strong>Rule: POST must be used to create a resource</strong></p></li><li><p><strong>Rule: POST must be used to execute a controller</strong></p></li><li><p><strong>Rule: DELETE must be used to delete a resource</strong></p></li><li><p><strong>Rule: OPTIONS must be used to retrieve supported HTTP methods</strong></p></li><li><p><strong>Rule : Use HTTP Status Codes to Indicate Response Status</strong></p></li></ul><p>HTTP status codes are used to indicate the response status of an HTTP request. The following table lists the HTTP status codes and their corresponding meanings:</p><table><thead><tr><th>HTTP Status Code</th><th>Meaning</th><th>Information</th></tr></thead><tbody><tr><td>100</td><td>100 and above are information</td><td>100 and above are for "Information". You rarely use them directly. Responses with these status codes cannot have a body.</td></tr><tr><td>200 OK</td><td>The request was successful</td><td>200 and above are for "Successful" responses. These are the ones you would use the most. 200 is the default status code for a successful response.</td></tr><tr><td>201 Created</td><td>The request was successful and a resource was created</td><td>201 is "Created". This is used when a new resource is created. The response will contain a Location header with the URI of the new resource.</td></tr><tr><td>204 No Content</td><td>The request was successful but there is no representation to return</td><td>A special case is 204, "No Content". This response is used when there is no content to return to the client, and so the response must not have a body.</td></tr><tr><td>300 Multiple Choices</td><td>The requested resource corresponds to any one of a set of representations, each with its own specific location</td><td>300 and above are for "Redirection". These are used when the client needs to take some additional action in order to complete the request. For example, if you request a resource that has been moved to a different location, the response will be 301, "Moved Permanently", and the response will contain a Location header with the new location of the resource. The client can then make a new request to that location.</td></tr><tr><td>400 Bad Request</td><td>The request could not be understood by the server</td><td>400 and above are for "Client Error" responses. These are used when the client has made a mistake in its request. For example, if you request a resource that doesn't exist, the response will be 404, "Not Found".</td></tr><tr><td>401 Unauthorized</td><td>The request requires user authentication</td><td>401 is "Unauthorized". This is used when the client needs to authenticate itself to get the requested response.</td></tr><tr><td>403 Forbidden</td><td>The server understood the request, but is refusing to fulfill it</td><td>403 is "Forbidden". This is used when the client is not allowed to access the resource. For example, if you try to access a resource that you don't have permission to access, the response will be 403, "Forbidden".</td></tr><tr><td>404 Not Found</td><td>The server has not found anything matching the Request-URI</td><td>404 is "Not Found". This is used when the client requests a resource that doesn't exist. For example, if you request a resource that doesn't exist, the response will be 404, "Not Found".</td></tr><tr><td>405 Method Not Allowed</td><td>The method specified in the Request-Line is not allowed for the resource identified by the Request-URI</td><td>405 is "Method Not Allowed". This is used when the client requests a resource using a method that isn't allowed. For example, if you try to access a resource using the POST method, but the resource only supports the GET method, the response will be 405, "Method Not Allowed".</td></tr><tr><td>500 Internal Server Error</td><td>The server encountered an unexpected condition which prevented it from fulfilling the request</td><td>500 and above are for "Server Error" responses. These are used when the server encounters an error while fulfilling the request. For example, if the server runs out of memory while fulfilling the request, the response will be 500, "Internal Server Error".</td></tr></tbody></table><p>The approaches and best practices of REST API outlined in this blog article will help anyone follow consistent guidelines for designing and developing REST APIs. </p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="references">References<a class="hash-link" href="#references" title="Direct link to heading"></a></h2><ul><li><a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm" target="_blank" rel="noopener noreferrer">Roy Fielding's Dissertation</a></li><li><a href="https://restfulapi.net/" target="_blank" rel="noopener noreferrer">What is REST</a></li><li><a href="https://www.amazon.in/REST-API-Design-Rulebook-Consistent-ebook/dp/B005XE5A7Q/ref=sr_1_1?keywords=rest+api+design+rulebook&qid=1665926194&qu=eyJxc2MiOiIwLjQzIiwicXNhIjoiMC41NCIsInFzcCI6IjAuMDAifQ%3D%3D&sprefix=REST+API+D%2Caps%2C194&sr=8-1" target="_blank" rel="noopener noreferrer">REST API Design Rulebook</a></li><li><a href="https://www.amazon.in/Hands-RESTful-Design-Patterns-Practices-ebook/dp/B07BJL399D/ref=sr_1_2?keywords=rest+api+design+rulebook&qid=1665926194&qu=eyJxc2MiOiIwLjQzIiwicXNhIjoiMC41NCIsInFzcCI6IjAuMDAifQ%3D%3D&sprefix=REST+API+D%2Caps%2C194&sr=8-2" target="_blank" rel="noopener noreferrer">Hands-on RESTful API Design Patterns</a></li></ul>]]></content:encoded>
<category>rest</category>
<category>restapi</category>
<category>rest-api-design-rules</category>
</item>
<item>
<title><![CDATA[Understanding MongoDB Replicasets and Write Concern - Part 1]]></title>
<link>https://ivishalgandhi.github.io/mongodb-replicaset-write-concern-read-pref</link>
<guid>mongodb-replicaset-write-concern-read-pref</guid>
<pubDate>Sun, 21 Aug 2022 00:00:00 GMT</pubDate>
<description><![CDATA[Introducing Replicasets]]></description>
<content:encoded><![CDATA[<h2 class="anchor anchorWithStickyNavbar_LWe7" id="introducing-replicasets">Introducing Replicasets<a class="hash-link" href="#introducing-replicasets" title="Direct link to heading"></a></h2><p>The way to achieve fault tolerance in MongoDB is through the use of <code>replica sets</code>. </p><div></div><p>Two or more <code>secondary</code> nodes along with a <code>primary</code> node forms a replica set. Application makes all the read/write calls to the primary node which propagate all the write requests synchronously or asynchronously to the secondary nodes. </p><p>The Secondary nodes fetches the data via Oplog pull from Primary or other nodes. </p><p>The Primary node is responsible for all the writes and reads. The secondary nodes can be utilized for reads via <a href="https://docs.mongodb.com/manual/reference/method/Mongo.setSecondaryOk/" target="_blank" rel="noopener noreferrer"><code>setSecondaryOk</code></a> or <a href="https://docs.mongodb.com/manual/reference/read-preference/" target="_blank" rel="noopener noreferrer"><code>readPreference</code></a>. </p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="understanding-oplog">Understanding Oplog<a class="hash-link" href="#understanding-oplog" title="Direct link to heading"></a></h2><p>When the application performs a write, the primary node applies the write to the database like a standalone. </p><p>The difference between Replicaset write and standalone write is that replica set nodes have an <code>OpObserver</code> that inserts a document to the <strong>oplog</strong> whenever a write to the database happens, describing the write. The <strong>oplog</strong> is a capped collection called <code>oplog.rs</code> in the <code>local</code> database. </p><p>For every operation performed in a write, the primary node inserts a document into the oplog. The oplog is a capped collection, which means that it has a maximum size. When the oplog reaches its maximum size, MongoDB removes the oldest entries to make room for new entries. </p><p>For a write which performs create collection and insert, there are two oplog entries created one for <code>create</code> collection and another for <code>insert</code>.</p><div class="language-cpp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cpp codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic">// mongod_main.cpp</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token function" style="color:#d73a49">setUpObservers</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">service</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><div class="language-cpp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cpp codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token comment" style="color:#999988;font-style:italic">//op_observer_registry.h</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">onCreateCollection</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">OperationContext</span><span class="token operator" style="color:#393A34">*</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> opCtx</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> CollectionPtr</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> coll</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> NamespaceString</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> collectionName</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> CollectionOptions</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> options</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> BSONObj</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> idIndex</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> OplogSlot</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> createOpTime</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">bool</span><span class="token plain"> fromMigrate</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">override</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ReservedTimes times</span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain">opCtx</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">auto</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> o </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> _observers</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> o</span><span class="token operator" style="color:#393A34">-></span><span class="token function" style="color:#d73a49">onCreateCollection</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> opCtx</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> coll</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> collectionName</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> options</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> idIndex</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> createOpTime</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> fromMigrate</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">using</span><span class="token plain"> OpObserver</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">onInserts</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">onInserts</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">OperationContext</span><span class="token operator" style="color:#393A34">*</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> opCtx</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> NamespaceString</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> nss</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> UUID</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> uuid</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> std</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">vector</span><span class="token operator" style="color:#393A34"><</span><span class="token plain">InsertStatement</span><span class="token operator" style="color:#393A34">></span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">const_iterator begin</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> std</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">vector</span><span class="token operator" style="color:#393A34"><</span><span class="token plain">InsertStatement</span><span class="token operator" style="color:#393A34">></span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">const_iterator end</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">bool</span><span class="token plain"> fromMigrate</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">override</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ReservedTimes times</span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain">opCtx</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">auto</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> o </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> _observers</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> o</span><span class="token operator" style="color:#393A34">-></span><span class="token function" style="color:#d73a49">onInserts</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">opCtx</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> nss</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> uuid</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> begin</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> end</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> fromMigrate</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h2 class="anchor anchorWithStickyNavbar_LWe7" id="understanding-write-concern">Understanding Write Concern<a class="hash-link" href="#understanding-write-concern" title="Direct link to heading"></a></h2><p>Write concern is a way to ensure that the write operations are propagated to the secondary nodes.</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="default-write-concern">Default Write Concern<a class="hash-link" href="#default-write-concern" title="Direct link to heading"></a></h3><p>If a write operation does not explicitly specify a write concern, the server will use a default
write concern. </p><p>This default write concern will be defined by either the</p><ul><li><strong>Cluster-Wide write concern</strong>, explicitly set by the user
or</li><li><strong>Implicit Default write concern</strong>, implicitly set by the server based on replica set configuration.</li></ul><h4 class="anchor anchorWithStickyNavbar_LWe7" id="cluster-wide-write-concern">Cluster-Wide Write Concern<a class="hash-link" href="#cluster-wide-write-concern" title="Direct link to heading"></a></h4><p>The cluster-wide write concern is set by the user using the <a href="https://docs.mongodb.com/manual/reference/command/setDefaultRWConcern/" target="_blank" rel="noopener noreferrer"><code>setDefaultRWConcern</code></a> command. Setting the cluster-wide write concern will cause the implicit default write concern not to take effect.</p><p>On a sharded cluster, the cluster-wide write concern is set on the config server. On a replica set, the cluster-wide write concern is set on the primary node. The below code snippets shows how the cluster-wide write concern is set on the primary node and stored on the config node. </p><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">adminCommand</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">setDefaultRWConcern</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">defaultReadConcern</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token operator" style="color:#393A34"><</span><span class="token plain">read concern</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">defaultWriteConcern</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token operator" style="color:#393A34"><</span><span class="token plain">write concern</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">writeConcern</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token operator" style="color:#393A34"><</span><span class="token plain">write concern</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">comment</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token operator" style="color:#393A34"><</span><span class="token plain">any</span><span class="token operator" style="color:#393A34">></span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">)</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><div class="language-cpp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cpp codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic">//cluster_rwc_defaults_commands.cpp </span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">class</span><span class="token plain"> </span><span class="token class-name">ClusterSetDefaultRWConcernCommand</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token base-clause keyword" style="color:#00009f">public</span><span class="token base-clause"> </span><span class="token base-clause class-name">BasicCommand</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">public</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">ClusterSetDefaultRWConcernCommand</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">BasicCommand</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"setDefaultRWConcern"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">bool</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">run</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">OperationContext</span><span class="token operator" style="color:#393A34">*</span><span class="token plain"> opCtx</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> DatabaseName</span><span class="token operator" style="color:#393A34">&</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> BSONObj</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> cmdObj</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> BSONObjBuilder</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">override</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">auto</span><span class="token plain"> configShard </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token class-name">Grid</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">get</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">opCtx</span><span class="token punctuation" style="color:#393A34">)</span><span class="token operator" style="color:#393A34">-></span><span class="token function" style="color:#d73a49">shardRegistry</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token operator" style="color:#393A34">-></span><span class="token function" style="color:#d73a49">getConfigShard</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">auto</span><span class="token plain"> cmdResponse </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">uassertStatusOK</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">configShard</span><span class="token operator" style="color:#393A34">-></span><span class="token function" style="color:#d73a49">runCommandWithFixedRetryAttempts</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> opCtx</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">ReadPreferenceSetting</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">ReadPreference</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">PrimaryOnly</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> NamespaceString</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">kAdminDb</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">toString</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">CommandHelpers</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">appendMajorityWriteConcern</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">CommandHelpers</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">filterCommandRequestForPassthrough</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">cmdObj</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> opCtx</span><span class="token operator" style="color:#393A34">-></span><span class="token function" style="color:#d73a49">getWriteConcern</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> Shard</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">RetryPolicy</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">kNotIdempotent</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">uassertStatusOK</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">cmdResponse</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">commandStatus</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">uassertStatusOK</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">cmdResponse</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">writeConcernStatus</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// Quickly pick up the new defaults by setting them in the cache.</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">auto</span><span class="token plain"> newDefaults </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token class-name">RWConcernDefault</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">parse</span><span class="token punctuation" style="color:#393A34">(</span><span class="token function" style="color:#d73a49">IDLParserContext</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"ClusterSetDefaultRWConcern"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> cmdResponse</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">response</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">auto</span><span class="token plain"> optWC </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> newDefaults</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getDefaultWriteConcern</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">optWC</span><span class="token operator" style="color:#393A34">-></span><span class="token function" style="color:#d73a49">hasCustomWriteMode</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">LOGV2_WARNING</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token number" style="color:#36acaa">6081700</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"A custom write concern is being set as the default write concern in a sharded "</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"cluster. This set is unchecked, but if the custom write concern does not "</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"exist on all shards in the cluster, errors will occur upon writes"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"customWriteConcern"</span><span class="token plain">_attr </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> stdx</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token generic-function function" style="color:#d73a49">get</span><span class="token generic-function generic class-name operator" style="color:#393A34"><</span><span class="token generic-function generic class-name">std</span><span class="token generic-function generic class-name double-colon punctuation" style="color:#393A34">::</span><span class="token generic-function generic class-name">string</span><span class="token generic-function generic class-name operator" style="color:#393A34">></span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">optWC</span><span class="token operator" style="color:#393A34">-></span><span class="token plain">w</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">ReadWriteConcernDefaults</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">get</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">opCtx</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">setDefault</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">opCtx</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> std</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">move</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">newDefaults</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">CommandHelpers</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">filterCommandReplyForPassthrough</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">cmdResponse</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">response</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">&</span><span class="token plain">result</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">true</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h4 class="anchor anchorWithStickyNavbar_LWe7" id="implicit-default-write-concern">Implicit default write concern<a class="hash-link" href="#implicit-default-write-concern" title="Direct link to heading"></a></h4><p>The implicit default write concern is calculated and set on startup by the server based on the replica set configuration. The server will set the implicit default write concern to the following:</p><ul><li>If the replica set has a single node, the implicit default write concern is <code>{ w: 1 }</code></li><li>For most of the cases the implicit default write concern is <code>{ w: "majority" }</code></li></ul><h5 class="anchor anchorWithStickyNavbar_LWe7" id="psa">PSA<a class="hash-link" href="#psa" title="Direct link to heading"></a></h5><p><code>implicitDefaultWriteConcern = if ((#arbiters > 0) AND (#non-arbiters <= majority(#voting nodes)) then {w:1} else {w:majority}</code></p><p>Implicit default to a value that the set can satisfy in the event of one data-bearing node
going down. That is, the number of data-bearing nodes must be strictly greater than the majority
of voting nodes for the set to set <code>{w: "majority"}</code>.</p><p>For example, if we have a PSA replica set, and the secondary goes down, the primary cannot
successfully acknowledge a majority write as the majority for the set is two nodes. However, the
primary will remain primary with the arbiter's vote. In this case, the DWCF will have preemptively
set the IDWC to <code>{w: 1}</code> so the user can still perform writes to the replica set.</p><h5 class="anchor anchorWithStickyNavbar_LWe7" id="sharded-cluster">Sharded Cluster<a class="hash-link" href="#sharded-cluster" title="Direct link to heading"></a></h5><p>For a sharded cluster, the implicit default write concern is set to <code>{ w: "majority" }</code> if the
cluster has a majority of voting nodes. Otherwise, the implicit default write concern is set to
<code>{ w: 1 }</code>.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="understanding-secondary-nodes-operations">Understanding Secondary Nodes Operations<a class="hash-link" href="#understanding-secondary-nodes-operations" title="Direct link to heading"></a></h2><p>The secondary nodes will choose the node with the highest <code>lastApplied</code> timestamp as the<strong> sync source</strong>. The secondary nodes will then <strong>pull</strong> the oplog entries from the sync source and apply them to its own oplog.</p><p>The Secondary will also keep its <strong>sync source</strong> uptodate with its progress, this helps primary satisfy the read concern. </p><p>Here are the high level steps performed to select and probe the sync source</p><ol><li><code>TopologyCoordinator</code> checks if user requested a specific sync source using <code>replSetSyncFrom</code> command. If so, it will use that sync source. Otherwise, it will use the sync source from the last successful election.</li><li>Check if <strong>chaining</strong> is disabled. If so, the secondary will always use primary as its sync source </li></ol><div class="language-cpp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cpp codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">chainingPreference </span><span class="token operator" style="color:#393A34">==</span><span class="token plain"> ChainingPreference</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">kUseConfiguration </span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token operator" style="color:#393A34">!</span><span class="token plain">_rsConfig</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">isChainingAllowed</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">_currentPrimaryIndex </span><span class="token operator" style="color:#393A34">==</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">-</span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">LOG</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token operator" style="color:#393A34"><<</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Cannot select a sync source because chaining is"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">" not allowed and primary is unknown/down"</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> _syncSource </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">HostAndPort</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> _syncSource</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">else</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token function" style="color:#d73a49">_memberIsBlacklisted</span><span class="token punctuation" style="color:#393A34">(</span><span class="token operator" style="color:#393A34">*</span><span class="token function" style="color:#d73a49">_currentPrimaryMember</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> now</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">LOG</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token operator" style="color:#393A34"><<</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Cannot select a sync source because chaining is not allowed and primary "</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"member is blacklisted: "</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token operator" style="color:#393A34"><<</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">_currentPrimaryMember</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token operator" style="color:#393A34">-></span><span class="token function" style="color:#d73a49">getHostAndPort</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> _syncSource </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">HostAndPort</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> _syncSource</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ol start="3"><li>Fetch latest opTime. Do not sync from a node where newest oplog is more than <code>maxSyncSourceLagSecs</code></li></ol><div class="language-cpp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cpp codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">_currentPrimaryIndex </span><span class="token operator" style="color:#393A34">!=</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">-</span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> OpTime primaryOpTime </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> _memberData</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">at</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">_currentPrimaryIndex</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getHeartbeatAppliedOpTime</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// Check if primaryOpTime is still close to 0 because we haven't received</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// our first heartbeat from a new primary yet.</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">unsigned</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> maxLag </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token generic-function function" style="color:#d73a49">static_cast</span><span class="token generic-function generic class-name operator" style="color:#393A34"><</span><span class="token generic-function generic class-name keyword" style="color:#00009f">unsigned</span><span class="token generic-function generic class-name"> </span><span class="token generic-function generic class-name keyword" style="color:#00009f">int</span><span class="token generic-function generic class-name operator" style="color:#393A34">></span><span class="token punctuation" style="color:#393A34">(</span><span class="token generic-function function" style="color:#d73a49">durationCount</span><span class="token generic-function generic class-name operator" style="color:#393A34"><</span><span class="token generic-function generic class-name">Seconds</span><span class="token generic-function generic class-name operator" style="color:#393A34">></span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">_options</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">maxSyncSourceLagSecs</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">primaryOpTime</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getSecs</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">>=</span><span class="token plain"> maxLag</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> oldestSyncOpTime </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">OpTime</span><span class="token punctuation" style="color:#393A34">(</span><span class="token function" style="color:#d73a49">Timestamp</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">primaryOpTime</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getSecs</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">-</span><span class="token plain"> maxLag</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> primaryOpTime</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getTerm</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ol start="4"><li>Loop through all the nodes and find the closest node which satisfies the condition </li></ol><div class="language-cpp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cpp codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">HostAndPort </span><span class="token class-name">TopologyCoordinator</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">chooseNewSyncSource</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">Date_t now</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> OpTime</span><span class="token operator" style="color:#393A34">&</span><span class="token plain"> lastOpTimeFetched</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ChainingPreference chainingPreference</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">.</span><span class="token punctuation" style="color:#393A34">.</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">.</span><span class="token punctuation" style="color:#393A34">.</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">.</span><span class="token punctuation" style="color:#393A34">.</span><span class="token punctuation" style="color:#393A34">.</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="oplog-fetching">Oplog Fetching<a class="hash-link" href="#oplog-fetching" title="Direct link to heading"></a></h3><p>The secondary node will fetch the oplog entries from the sync source to keep its data syncronized. The entire implementation of the oplog fetching is in the <code>OplogFetcher</code> class which runs in a separate thread and communicates via a dedicated client connection.</p><div class="language-cpp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cpp codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token class-name">OplogFetcher</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">setConnection</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">std</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token plain">unique_ptr</span><span class="token operator" style="color:#393A34"><</span><span class="token plain">DBClientConnection</span><span class="token operator" style="color:#393A34">></span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"> _connectedClient</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// Can only call this once, before startup.</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">invariant</span><span class="token punctuation" style="color:#393A34">(</span><span class="token operator" style="color:#393A34">!</span><span class="token plain">_conn</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> _conn </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> std</span><span class="token double-colon punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">move</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">_connectedClient</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>]]></content:encoded>
<category>mongodb</category>
<category>replicaset</category>
<category>write-concern</category>
</item>
<item>
<title><![CDATA[Guide to Software Bill of Materials(SBoM) and Docker SBOM CLI]]></title>
<link>https://ivishalgandhi.github.io/docker-sbom</link>
<guid>docker-sbom</guid>
<pubDate>Sat, 09 Jul 2022 00:00:00 GMT</pubDate>
<description><![CDATA[An Software Bill of Materials (SBoM) is a formal record containing the details and supply chain relationships of various components used in building the software. These components, including libraries and modules, can be proprietary or open source,free or paid and the data can be widely available or access-restricted.]]></description>
<content:encoded><![CDATA[<p>An <strong>Software Bill of Materials (SBoM)</strong> is a formal record containing the details and supply chain relationships of various components used in building the software. These components, including libraries and modules, can be proprietary or open source,free or paid and the data can be widely available or access-restricted.</p><p><img loading="lazy" src="/assets/images/sbom-e9e0845791a6a0077ec17fe1845f4c36.webp" width="1024" height="652" class="img_ev3q"></p><p>SBoM is analogous to a list of ingredients on food packaging. In May 2021, the US President released the <a href="https://www.whitehouse.gov/briefing-room/presidential-actions/2021/05/12/executive-order-on-improving-the-nations-cybersecurity/" target="_blank" rel="noopener noreferrer">Executive Order</a> on improving the Nation’s Cybersecurity. The Software Bill of Materials (SBoM) directly impacts all developers. The SBoM requires third-party software companies to provide customers with the code equivalent of a “nutrition chart.”</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="when-should-sbom-be-used--use-cases-">When should SBoM be used – Use cases ?<a class="hash-link" href="#when-should-sbom-be-used--use-cases-" title="Direct link to heading"></a></h2><ul><li><p><strong>Developing products</strong></p><ul><li>Scan vulnerabilities in the components</li><li>Keep codebase to bare minimum, reduce the number of dependencies and size</li><li>Generate SBoM for end users</li></ul></li><li><p><strong>IT Operations</strong></p><ul><li>Understand operational risk</li><li>Understand potential exploitations</li><li>Real time asset inventory</li><li>Software Selection</li><li>Identify known vulnerabilities and compliance</li></ul></li><li><p><strong>EOL</strong></p><ul><li>Complete visibility to components before evaluation or deploying in production</li><li>Understand the software architecture and the dependencies of the software</li></ul></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="why-sbom-">Why SBOM ?<a class="hash-link" href="#why-sbom-" title="Direct link to heading"></a></h2><ul><li><p>Requirement from regulatory bodies to track the components used in the software</p></li><li><p>Transparency of components getting shipped</p></li><li><p>Container ecosystem has exploded and the need to track the components getting shipped is a must</p></li><li><p>Software Vulnerabilities are bugs</p></li><li><p>Detecting and remediating Vulnerabilities</p></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="sbom-formats">SBOM Formats<a class="hash-link" href="#sbom-formats" title="Direct link to heading"></a></h2><ul><li><p><strong>SPDX (Software Package Data Exchange )</strong></p><ul><li>Open standard for communicating software bill of material information, including components, licenses, copyrights and security references. Reduces redundant work by providing a common format for organizations and communities to share and use</li></ul></li><li><p><strong>CycloneDX</strong></p><ul><li>Open Web Application Security Project(OWASP) CycloneDX is a lightweight Software Bill of Materials (SBOM) standard designed for use in application security contexts and supply chain component analysis.</li></ul></li><li><p><strong>SWID (Software Identification Tags)</strong></p><ul><li>SWID is used primarily to identify installed software and is the preferred format of the NVD. SWID tags are used in the National Vulnerability Database to describe vulnerable components. The CycloneDX specification compliments this work as CycloneDX documents can incorporate SWID tags and other high-level SWID metadata and optionally include entire SWID documents. Use of SWID tag ID’s are useful in determining if a specific component has known vulnerabilities.</li></ul></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="docker-desktop--sbom-cli">Docker Desktop – SBOM CLI<a class="hash-link" href="#docker-desktop--sbom-cli" title="Direct link to heading"></a></h2><p>In Docker Desktop 4.7.0 Docker introduced and included a new experimental docker sbom CLI that is used for displaying SBoM for any container image. docker sbom scans the layer of container images using the Syft Project</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="usage">Usage<a class="hash-link" href="#usage" title="Direct link to heading"></a></h2><ul><li>Display SBOM in CyloneDX format</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> sbom mongo:latest --format cyclonedx-json </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">more</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"type"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"library"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"publisher"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"MongoDB Packaging </span><span class="token string entity" style="color:#36acaa">\u003c</span><span class="token string" style="color:#e3116c">[email protected]</span><span class="token string entity" style="color:#36acaa">\u003e</span><span class="token string" style="color:#e3116c">"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"name"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongodb-org-server"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"version"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"5.0.9"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"cpe"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"cpe:2.3:a:mongodb-org-server:mongodb-org-server:5.0.9:*:*:*:*:*:*:*"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"purl"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"pkg:deb/ubuntu/[email protected]?arch=arm64</span><span class="token string entity" style="color:#36acaa">\u0026</span><span class="token string" style="color:#e3116c">upstream=mongodb-org</span><span class="token string entity" style="color:#36acaa">\u0026</span><span class="token string" style="color:#e3116c">distro=ubuntu-20.04"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"properties"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"name"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"syft:package:foundBy"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"value"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"dpkgdb-cataloger"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"name"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"syft:package:metadataType"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"value"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"DpkgMetadata"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Display SBOM summary of packages. e.g. using the below command we can check for the log4j vulnerabilities</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> sbom neo4j </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">grep</span><span class="token plain"> log4j</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log4j-api </span><span class="token number" style="color:#36acaa">2.17</span><span class="token plain">.1 java-archive</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log4j-core </span><span class="token number" style="color:#36acaa">2.17</span><span class="token plain">.1 java-archive</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> sbom neo4j:4.4.1 </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">grep</span><span class="token plain"> log4j</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log4j-api </span><span class="token number" style="color:#36acaa">2.15</span><span class="token plain">.0 java-archive</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log4j-core </span><span class="token number" style="color:#36acaa">2.15</span><span class="token plain">.0 java-archive</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> sbom elasticsearch:7.16.3 </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">grep</span><span class="token plain"> log4j</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">elasticsearch-log4j </span><span class="token number" style="color:#36acaa">7.16</span><span class="token plain">.3 java-archive</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log4j-1.2-api </span><span class="token number" style="color:#36acaa">2.17</span><span class="token plain">.1 java-archive</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log4j-api </span><span class="token number" style="color:#36acaa">2.17</span><span class="token plain">.1 java-archive</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log4j-core </span><span class="token number" style="color:#36acaa">2.17</span><span class="token plain">.1 java-archive</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log4j-slf4j-impl </span><span class="token number" style="color:#36acaa">2.17</span><span class="token plain">.1 java-archive</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>There are many benefits to generate SBOM for compliance and vulnerability analysis. Further SBOM can be used for input to open source vulnerability databases like <a href="https://github.com/snyk/cli" target="_blank" rel="noopener noreferrer">Snyk</a> and open source vulnerability scanning tools like <a href="https://github.com/anchore/grype" target="_blank" rel="noopener noreferrer">Grype</a></p>]]></content:encoded>
<category>docker-desktop</category>
<category>SBOM</category>
<category>docker</category>
</item>
<item>
<title><![CDATA[How to configure Percona MongoDB Replicaset, Percona Backup Manager, Backup Agent using Docker and perform Replicaset backup, restore using S3 compatible object storage – MINIO]]></title>
<link>https://ivishalgandhi.github.io/percona-mongo-replicaset-minio</link>
<guid>percona-mongo-replicaset-minio</guid>
<pubDate>Sun, 29 May 2022 00:00:00 GMT</pubDate>
<description><![CDATA[In this blog post, i will walk you through the steps required to containerize Percona Server for MongoDB, Percona Backup Manager, and Agent from source and configure cloud-native S3(Simple Storage Service) compatible distributed object storage MINIO to backup and restore Percona MongoDB snapshot backups.]]></description>
<content:encoded><![CDATA[<p>In this blog post, i will walk you through the steps required to containerize <a href="https://github.com/percona/percona-server-mongodb" target="_blank" rel="noopener noreferrer">Percona Server for MongoDB</a>, <a href="https://github.com/percona/percona-backup-mongodb" target="_blank" rel="noopener noreferrer">Percona Backup Manager</a>, and Agent from source and configure cloud-native S3(<strong>S</strong>imple <strong>S</strong>torage <strong>S</strong>ervice) compatible distributed object storage <a href="https://min.io/" target="_blank" rel="noopener noreferrer">MINIO</a> to backup and restore Percona MongoDB snapshot backups.</p><p><img loading="lazy" src="/assets/images/minio-be0df17e540f83ca7fda66435ae2b18c.webp" width="834" height="433" class="img_ev3q"></p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a class="hash-link" href="#prerequisites" title="Direct link to heading"></a></h2><p>Ensure the below binaries are installed before starting the setup and configuration</p><p><a href="https://www.docker.com/get-started/" target="_blank" rel="noopener noreferrer">Docker</a> or <a href="https://podman.io/" target="_blank" rel="noopener noreferrer">Podman</a> to containerize Percona MongoDB replicaset and PBM Agent
<a href="https://docs.docker.com/compose/install/" target="_blank" rel="noopener noreferrer">Docker Compose</a>
<a href="https://go.dev/learn/" target="_blank" rel="noopener noreferrer">Golang</a> compiler – Build Percona Backup Manager binaries
<a href="https://www.portainer.io/" target="_blank" rel="noopener noreferrer">Portainer</a> (Optional) – Intuitive UI for container configuration and monitoring
Let us perform the below steps to set up PSMDB Replicaset; PBM Agent; Minio, S3 compatible bucket, and PBM configuration to perform backups and restores from the bucket.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="steps">Steps<a class="hash-link" href="#steps" title="Direct link to heading"></a></h2><ul><li>Create the Docker environment file with Docker Image, tag, port, and replicaset information. Save the file as .env in the working directory</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token assign-left variable" style="color:#36acaa">MONGODB_IMAGE</span><span class="token operator" style="color:#393A34">=</span><span class="token plain">percona/percona-server-mongodb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token assign-left variable" style="color:#36acaa">MONGODB_VERSION</span><span class="token operator" style="color:#393A34">=</span><span class="token number" style="color:#36acaa">5.0</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token assign-left variable" style="color:#36acaa">MONGO1_PORT</span><span class="token operator" style="color:#393A34">=</span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:15000</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token assign-left variable" style="color:#36acaa">MONGO2_PORT</span><span class="token operator" style="color:#393A34">=</span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:15001</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token assign-left variable" style="color:#36acaa">MONGO3_PORT</span><span class="token operator" style="color:#393A34">=</span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:15002</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token assign-left variable" style="color:#36acaa">MONGODB_PORT</span><span class="token operator" style="color:#393A34">=</span><span class="token number" style="color:#36acaa">27017</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token assign-left variable" style="color:#36acaa">MONGODB_DOCKER_NETWORK</span><span class="token operator" style="color:#393A34">=</span><span class="token plain">mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token assign-left variable" style="color:#36acaa">RS_NAME</span><span class="token operator" style="color:#393A34">=</span><span class="token plain">rs1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Create keyFile , Dockerfile and download percona-backup-manager source code in the working directory</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">git</span><span class="token plain"> clone https://github.com/percona/percona-backup-mongodb.git</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">ARG MONGODB_VERSION</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">ARG MONGODB_IMAGE</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">FROM </span><span class="token variable" style="color:#36acaa">${MONGODB_IMAGE}</span><span class="token builtin class-name">:</span><span class="token variable" style="color:#36acaa">${MONGODB_VERSION}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token environment constant" style="color:#36acaa">USER</span><span class="token plain"> root</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">COPY keyFile /opt/keyFile</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">RUN </span><span class="token function" style="color:#d73a49">chown</span><span class="token plain"> mongodb /opt/keyFile </span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">chmod</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">400</span><span class="token plain"> /opt/keyFile </span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">mkdir</span><span class="token plain"> -p /home/mongodb/ </span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">chown</span><span class="token plain"> mongodb /home/mongodb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token environment constant" style="color:#36acaa">USER</span><span class="token plain"> mongodb</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Create Docker Compose file</li></ul><div class="language-YAML codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-YAML codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">version: "3.8"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">services:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs101:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> build:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> dockerfile: Dockerfile</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> context: /home/vishal/dev/psmdb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> args:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_VERSION=${MONGODB_VERSION}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_IMAGE=${MONGODB_IMAGE}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: rs101</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=mongod"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> environment:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - REPLSET_NAME=rs1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGO_USER=dba</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - BACKUP_USER=bcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGO_PASS=test1234</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "${MONGO1_PORT}:${MONGODB_PORT}"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> # command: mongod --replSet rs1 --port ${MONGO1_PORT}:27017 --storageEngine wiredTiger --keyFile /opt/keyFile --wiredTigerCacheSizeGB 1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["--replSet", "${RS_NAME}", "--bind_ip_all", "--storageEngine", "wiredTiger" , "--keyFile", "/opt/keyFile"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - data-rs101:/data/db</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ./scripts/start.sh:/opt/start.sh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs102:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> build:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> dockerfile: Dockerfile</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> context: /home/vishal/dev/psmdb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> args:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_VERSION=${MONGODB_VERSION}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_IMAGE=${MONGODB_IMAGE}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: rs102</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=mongod"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> # command: mongod --replSet rs1 --port 27017 --storageEngine wiredTiger --keyFile /opt/keyFile --wiredTigerCacheSizeGB 1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "${MONGO2_PORT}:${MONGODB_PORT}"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["--replSet", "${RS_NAME}", "--bind_ip_all", "--storageEngine", "wiredTiger" , "--keyFile", "/opt/keyFile"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - data-rs102:/data/db</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs103:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> build:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> dockerfile: Dockerfile</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> context: /home/vishal/dev/psmdb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> args:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_VERSION=${MONGODB_VERSION}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_IMAGE=${MONGODB_IMAGE}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: rs103</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=mongod"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> # command: mongod --replSet rs1 --port 27017 --storageEngine wiredTiger --keyFile /opt/keyFile --wiredTigerCacheSizeGB 1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "${MONGO3_PORT}:${MONGODB_PORT}"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["--replSet", "${RS_NAME}", "--bind_ip_all", "--storageEngine", "wiredTiger" , "--keyFile", "/opt/keyFile"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - data-rs103:/data/db</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> agent-rs101:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: "pbmagent_rs101"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> user: "1001"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=agent"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.agent.rs=rs1"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> environment:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "PBM_MONGODB_URI=mongodb://${BACKUP_USER:-bcp}:${MONGO_PASS:-test1234}@rs101:27017"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> build:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=agent"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> dockerfile: /home/vishal/open-source/percona-backup-mongodb/docker/Dockerfile</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> context: /home/vishal/open-source/percona-backup-mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> args:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_VERSION=${MONGODB_VERSION:-5.0}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ./conf:/etc/pbm</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ./backups:/opt/backups</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - data-rs101:/data/db</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: pbm-agent</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> cap_add:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - NET_ADMIN</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> agent-rs102:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: "pbmagent_rs102"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> user: "1001"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=agent"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.agent.rs=rs1"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> environment:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "PBM_MONGODB_URI=mongodb://${BACKUP_USER:-bcp}:${MONGO_PASS:-test1234}@rs102:27017"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> build:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=agent"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> dockerfile: /home/vishal/open-source/percona-backup-mongodb/docker/Dockerfile</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> context: /home/vishal/open-source/percona-backup-mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> args:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_VERSION=${MONGODB_VERSION:-5.0}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ./conf:/etc/pbm</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ./backups:/opt/backups</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - data-rs102:/data/db</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: pbm-agent</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> cap_add:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - NET_ADMIN</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> agent-rs103:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: "pbmagent_rs103"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> user: "1001"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=agent"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.agent.rs=rs1"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> environment:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "PBM_MONGODB_URI=mongodb://${BACKUP_USER:-bcp}:${MONGO_PASS:-test1234}@rs103:27017"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> build:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> labels:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - "com.percona.pbm.app=agent"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> dockerfile: /home/vishal/open-source/percona-backup-mongodb/docker/Dockerfile</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> context: /home/vishal/open-source/percona-backup-mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> args:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - MONGODB_VERSION=${MONGODB_VERSION:-5.0}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ./conf:/etc/pbm</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ./backups:/opt/backups</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - data-rs103:/data/db</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: pbm-agent</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> cap_add:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - NET_ADMIN</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> backups: null</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> data-rs101: null</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> data-rs102: null</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> data-rs103: null</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Run Docker compose
The below command will build and start the docker container for Percona Server MongoDB Primary Secondary Secondary replicaset and Percona Backup Manager Agent for each replicaset</li></ul><div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ psmdb docker compose -f docker-compose-rs.yaml up -d</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">[+] Running 8/8</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">⠿ Container psmdb-rs102-1 Running 0.0s</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">⠿ Container psmdb-rs103-1 Running 0.0s</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">⠿ Container pbmagent_rs103 Running 0.0s</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">⠿ Container pbmagent_rs102 Running 0.0s</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">⠿ Container psmdb-rs101-1 Running 0.0s</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">⠿ Container pbmagent_rs101 Running 0.0s</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Connect to MongoDB replicaset and ensure replication and containers are working</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ mongo </span><span class="token string" style="color:#e3116c">"mongodb://dba:[email protected]:15000,192.168.50.113:15001,192.168.50.113:15002/admin?replicaSet=rs1"</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Setup Minio and Minio CLI</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token builtin class-name">cd</span><span class="token plain"> ~/downloads </span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">wget</span><span class="token plain"> https://dl.min.io/server/minio/release/linux-amd64/minio</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">wget</span><span class="token plain"> https://dl.min.io/client/mc/release/linux-amd64/mc</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token function" style="color:#d73a49">chmod</span><span class="token plain"> +x </span><span class="token function" style="color:#d73a49">mc</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">./mc --help</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ downloads ./minio server /home/vishal/data --address</span><span class="token operator" style="color:#393A34">=</span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:7000</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">API: http://0.0.0.0:7000 </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">RootUser: minioadmin </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">RootPass: minioadmin </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">Finished loading IAM sub-system </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">took </span><span class="token number" style="color:#36acaa">0</span><span class="token plain">.0s of </span><span class="token number" style="color:#36acaa">0</span><span class="token plain">.0s to load data</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">.</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">Console: http://192.168.50.113:43859 http://192.168.160.1:43859 http://172.18.0.1:43859 http://172.19.0.1:43859 http://172.24.0.1:43859 http://172.26.0.1:43859 http://172.17.0.1:43859 http://127.0.0.1:43859 </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">RootUser: minioadmin </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">RootPass: minioadmin </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">Command-line: https://docs.min.io/docs/minio-client-quickstart-guide</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> $ </span><span class="token function" style="color:#d73a49">mc</span><span class="token plain"> </span><span class="token builtin class-name">alias</span><span class="token plain"> </span><span class="token builtin class-name">set</span><span class="token plain"> myminio http://0.0.0.0:7000 minioadmin minioadmin</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">Documentation: https://docs.min.io</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Setup Minio server alias and List buckets</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">mc</span><span class="token plain"> </span><span class="token builtin class-name">alias</span><span class="token plain"> </span><span class="token builtin class-name">set</span><span class="token plain"> minio-deb http://192.168.50.113:7000 minioadmin minioadmin</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">mc</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">ls</span><span class="token plain"> minio-deb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">[</span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29 </span><span class="token number" style="color:#36acaa">14</span><span class="token plain">:59:32 IST</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> 0B nocodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">[</span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29 00:19:41 IST</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> 0B typesense/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Create a new bucket and name it <code>pbm</code></li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">mc</span><span class="token plain"> </span><span class="token builtin class-name">alias</span><span class="token plain"> </span><span class="token builtin class-name">set</span><span class="token plain"> minio-deb http://192.168.50.113:7000 minioadmin minioadmin</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">mc</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">ls</span><span class="token plain"> minio-deb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29 </span><span class="token number" style="color:#36acaa">14</span><span class="token plain">:59:32 IST</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> 0B nocodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29 00:19:41 IST</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> 0B typesense/</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Setup PBM or compile PBM from the source repository</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">apt-get</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">install</span><span class="token plain"> -y libkrb5-dev</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token builtin class-name">cd</span><span class="token plain"> percona-backup-mongodb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">make</span><span class="token plain"> build</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">make</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">install</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>create pbm_config.YAML to be used for configuring PBM for using MINIO</li></ul><div class="language-YAML codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-YAML codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">storage:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> type: s3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> s3:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> endpointUrl: http://192.168.50.113:7000</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> bucket: pbm</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> credentials:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> access-key-id: "minioadmin"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> secret-access-key: "minioadmin"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Configure PBM</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ ./pbm config --file /home/vishal/dev/psmdb/pbm_config.yaml --mongodb-uri</span><span class="token operator" style="color:#393A34">=</span><span class="token string" style="color:#e3116c">"mongodb://bcp:[email protected]:15000/?replSetName=rs1"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Validate agent container logs and run the pbm list command. If MINIO is configured successfully, agent container logs shouldn’t log any errors.</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29T01:31:14.000+0000 D </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">resync</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> got backups list: 02022-05-29T01:31:14.000+0000 D </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">resync</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> got physical restores list: </span><span class="token number" style="color:#36acaa">0</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ bin git:</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">main</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> ./pbm list --mongodb-uri</span><span class="token operator" style="color:#393A34">=</span><span class="token string" style="color:#e3116c">"mongodb://bcp:[email protected]:15000/?replSetName=rs1"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">Backup snapshots:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29T01:29:12Z </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">complete: </span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29T01:29:16Z</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29T01:38:38Z </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">complete: </span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29T01:38:42Z</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29T04:04:44Z </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">complete: </span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29T04:04:48Z</span><span class="token punctuation" style="color:#393A34">]</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>To run PBM backup and restore execute the below commands</li></ul><div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ ./pbm backup --mongodb-uri</span><span class="token operator" style="color:#393A34">=</span><span class="token string" style="color:#e3116c">"mongodb://bcp:[email protected]:15000/?replSetName=rs1"</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ ./pbm restore </span><span class="token number" style="color:#36acaa">2022</span><span class="token plain">-05-29T04:04:44Z --mongodb-uri</span><span class="token operator" style="color:#393A34">=</span><span class="token plain">"mongodb:/</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>]]></content:encoded>
<category>mongodb</category>
<category>containers</category>
<category>docker</category>
<category>s3</category>
<category>minio</category>
<category>pbm</category>
</item>
<item>
<title><![CDATA[Local Home Lab DNS Setup with DNSMasq and NGINX]]></title>
<link>https://ivishalgandhi.github.io/local-home-lab</link>
<guid>local-home-lab</guid>
<pubDate>Sun, 10 Apr 2022 00:00:00 GMT</pubDate>
<description><![CDATA[As I explored and set up an increased number of FOSS software using containers(Docker and LXD) and virtual machines(Multipass) in my home lab environment, I realized the difficulty in remembering the different ports the applications and containers are running. The solution to address this problem was to have a Domain Name System for the local network, which works to resolve local and external addresses with a reverse proxy to redirect calls based on DNS resolution.]]></description>
<content:encoded><![CDATA[<p>As I explored and set up an increased number of FOSS software using containers(Docker and LXD) and virtual machines(Multipass) in my home lab environment, I realized the difficulty in remembering the different ports the applications and containers are running. The solution to address this problem was to have a Domain Name System for the local network, which works to resolve local and external addresses with a reverse proxy to redirect calls based on DNS resolution.</p><p>The below command lists the Docker Containers and ports the container are running on, the requirement is to create a domain for a home setup with domain homelab.net and access the containerized applications with appsmith.homelab.net; typesense.homelab.net; excalidraw.homelab.net</p><p>Let’s get the list of docker containers with port numbers</p><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic"># get container names and port numbers</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> container </span><span class="token function" style="color:#d73a49">ls</span><span class="token plain"> --format </span><span class="token string" style="color:#e3116c">"table {{.ID}}</span><span class="token string entity" style="color:#36acaa">\t</span><span class="token string" style="color:#e3116c">{{.Names}}</span><span class="token string entity" style="color:#36acaa">\t</span><span class="token string" style="color:#e3116c">{{.Ports}}"</span><span class="token plain"> -a</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">CONTAINER ID NAMES PORTS</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">cbb2ac402270 appsmith </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:9001-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">9001</span><span class="token plain">/tcp, </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:70-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">80</span><span class="token plain">/tcp, </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:444-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">443</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">c9875323b989 typesense_typesense-1_1 </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:8108-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">8108</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">c453288c8496 excalidraw </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:3001-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">80</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">5be5d33f1f50 k8s-control-plane </span><span class="token number" style="color:#36acaa">127.0</span><span class="token plain">.0.1:34589-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">6443</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">4140d2fbf7d5 mysql_nocodb_1 </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:8082-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">8080</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">e7310461bee9 mysql_root_db_1 </span><span class="token number" style="color:#36acaa">3306</span><span class="token plain">/tcp, </span><span class="token number" style="color:#36acaa">33060</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">9b56c33d45d5 meilisearch_ms_1 </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:7700-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">7700</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">9ac6a0e16b0e mongo2 </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:20002-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">27017</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">2aaf01d2233f mongo1 </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:20001-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">27017</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">860b521f97dc mongo3 </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:20003-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">27017</span><span class="token plain">/tcp</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">d8ad1ec3cab8 rethinkdb_rethinkdb_1 </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:28015-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">28015</span><span class="token plain">/tcp, </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:29015-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">29015</span><span class="token plain">/tcp, </span><span class="token number" style="color:#36acaa">0.0</span><span class="token plain">.0.0:8081-</span><span class="token operator" style="color:#393A34">></span><span class="token number" style="color:#36acaa">8080</span><span class="token plain">/tcp</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>The containers and applications running on the local home network as shown above do not have a public domain name, the option was to look for setting up a DNS server with <a href="https://thekelleys.org.uk/dnsmasq/doc.html" target="_blank" rel="noopener noreferrer">DNSMasq</a>, and a reverse proxy using <a href="https://www.nginx.com/" target="_blank" rel="noopener noreferrer">NGINX</a>. The containers may not be the only use case scenario for local DNS servers with <a href="https://thekelleys.org.uk/dnsmasq/doc.html" target="_blank" rel="noopener noreferrer">DNSMasq</a>, there could be many others like accessing a local file share across devices; accessing applications from a mobile device, and sharing a printer.</p><p><a href="https://thekelleys.org.uk/dnsmasq/doc.html" target="_blank" rel="noopener noreferrer">DNSMasq</a> - Dnsmasq provides network infrastructure for small networks: DNS, DHCP, router advertisement, and network boot. It is designed to be lightweight and has a small footprint, suitable for resource-constrained routers and firewalls.</p><p><a href="https://www.nginx.com/" target="_blank" rel="noopener noreferrer">NGINX</a> - Reverse Proxy – A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.</p><p><strong>Let us get started with the implementation steps for DNSMasq and NGINX. The below steps are performed on Ubuntu 20.04 (Debian-based distro).</strong></p><p>Before starting the installation of DNSMasq, </p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-1-disable-systemd-resolve-which-binds-to-port-53-the-default-port-for-dnsmasq">Step 1: Disable systemd-resolve which binds to port 53, the default port for DNSMasq<a class="hash-link" href="#step-1-disable-systemd-resolve-which-binds-to-port-53-the-default-port-for-dnsmasq" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> systemctl stop systemd-resolved</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> systemctl disable systemd-resolved</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-2-install-dnsutils-dnsmasq">Step 2: Install DNSUtils, DNSMasq<a class="hash-link" href="#step-2-install-dnsutils-dnsmasq" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">apt</span><span class="token plain"> update </span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">apt</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">install</span><span class="token plain"> dnsmasq </span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">apt</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">install</span><span class="token plain"> dnsutils</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-3-create-the-dnsmasq-configuration-file">Step 3: Create the DNSMasq configuration file<a class="hash-link" href="#step-3-create-the-dnsmasq-configuration-file" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token assign-left variable" style="color:#36acaa">dnsmasq_conf</span><span class="token operator" style="color:#393A34">=</span><span class="token string" style="color:#e3116c">"no-dhcp-interface=enp2s0f0</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">bogus-priv</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">domain=homelab.net</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">expand-hosts</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">local=/homelab.net/</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">domain-needed</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">no-resolv</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">no-poll</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">server=8.8.8.8</span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">server=8.8.4.4"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token builtin class-name">echo</span><span class="token plain"> -e </span><span class="token string" style="color:#e3116c">"</span><span class="token string variable" style="color:#36acaa">$dnsmasq_conf</span><span class="token string" style="color:#e3116c">"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">></span><span class="token plain"> /etc/dnsmasq.d/home-lab.net </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> systemctl restart dnsmasq</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-4-add-container-dns-records-in-the-fileetchosts-the-records-in-the-hosts-file-will-be-used-by-dnsmasq-for-client-responses">Step 4: Add container DNS records in the file./etc/hosts. The records in the hosts file will be used by DNSMasq for client responses<a class="hash-link" href="#step-4-add-container-dns-records-in-the-fileetchosts-the-records-in-the-hosts-file-will-be-used-by-dnsmasq-for-client-responses" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain"> $ </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">nano</span><span class="token plain"> /etc/hosts </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic"># add the below records to the hosts file</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">#Container DNS records</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic"># appsmith</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token number" style="color:#36acaa">192.168</span><span class="token plain">.20.113 appsmith</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic"># excalidraw</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token number" style="color:#36acaa">192.168</span><span class="token plain">.20.113 excalidraw</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic"># typesense</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token number" style="color:#36acaa">192.168</span><span class="token plain">.20.113 typesense</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-5-restart-dnsmasq-service">Step 5: Restart DNSMasq service<a class="hash-link" href="#step-5-restart-dnsmasq-service" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> systemctl restart dnsmasq.service</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-6-install-nginx">Step 6: Install NGINX<a class="hash-link" href="#step-6-install-nginx" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">apt</span><span class="token plain"> update </span><span class="token operator" style="color:#393A34">&&</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">apt</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">install</span><span class="token plain"> nginx</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-6-to-enable-reverse-proxy-feature-create-a-new-nginx-configuration-file-in-sites-enabled-directory">Step 6: To enable reverse proxy feature, create a new NGINX configuration file in <code>sites-enabled</code> directory<a class="hash-link" href="#step-6-to-enable-reverse-proxy-feature-create-a-new-nginx-configuration-file-in-sites-enabled-directory" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain"> $ </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">nano</span><span class="token plain"> /etc/nginx/sites-enabled/homelab.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> server </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> listen </span><span class="token number" style="color:#36acaa">80</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> listen </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">::</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain">:80</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> server_name typesense.homelab.net</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> location / </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> proxy_bind </span><span class="token number" style="color:#36acaa">192.168</span><span class="token plain">.20.113</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> proxy_pass http://localhost:3000</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> server </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> listen </span><span class="token number" style="color:#36acaa">80</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> listen </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">::</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain">:80</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> server_name appsmith.homelab.net</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> location / </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> proxy_bind </span><span class="token number" style="color:#36acaa">192.168</span><span class="token plain">.20.113</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> proxy_pass http://localhost:70</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> server </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> listen </span><span class="token number" style="color:#36acaa">80</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> listen </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">::</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain">:80</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> server_name excalidraw.homelab.net</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> location / </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> proxy_bind </span><span class="token number" style="color:#36acaa">192.168</span><span class="token plain">.20.113</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> proxy_pass http://localhost:3001</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>The <code>proxy_pass</code> argument will forward all incoming client requests to app.homelab.net to the respective app. The IP address and port number can be easily changed.</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-7-reload-nginx-for-the-configuration-to-take-into-effect">Step 7 reload NGINX for the configuration to take into effect<a class="hash-link" href="#step-7-reload-nginx-for-the-configuration-to-take-into-effect" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">sudo</span><span class="token plain"> systemctl reload nginx</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>After a successful implementation, we will be able to access container applications using domain URLs as seen in the below screenshot with three panes first pane is appsmith ; second pane is excalidraw and third pane is typesense.</p><p><img loading="lazy" alt="local-home-lab-snapshot" src="/assets/images/2022-07-19-23-09-57-8b3ba580a484e53a7d25c704b6bccf60.png" width="2047" height="1111" class="img_ev3q"></p>]]></content:encoded>
<category>reverse-proxy</category>
<category>NGINX</category>
<category>DNSMASQ</category>
<category>Lab</category>
</item>
<item>
<title><![CDATA[Configure Sharding in MongoDB on Docker Containers]]></title>
<link>https://ivishalgandhi.github.io/sharding-mongo-docker</link>
<guid>sharding-mongo-docker</guid>
<pubDate>Sat, 02 Oct 2021 00:00:00 GMT</pubDate>
<description><![CDATA[In my previous blog post, I posted about configuring Replica Set to meet high availability requirements.]]></description>
<content:encoded><![CDATA[<p>In my previous <a href="/mongodb-rs-docker-persistent-volume">blog</a> post, I posted about configuring Replica Set to meet high availability requirements.</p><p>In this post, i cover</p><ul><li>MongoDB Sharded Cluster Components</li><li>Steps to create MongoDB Sharded Cluster using Docker Compose</li><li>Add Replica Set as a Shard</li><li>Sharding Data</li><li>Verify Distribution of Data</li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="replica-set-vs-sharding">Replica Set vs Sharding<a class="hash-link" href="#replica-set-vs-sharding" title="Direct link to heading"></a></h2><p><strong>Replica Set</strong> is the way of keeping identical set of data on multiple servers. Sharding refers to the process of splitting data across nodes, also known as horizontal partitioning.</p><p>A database <strong>shard</strong>, is a horizontal partition of data in a database, each node contains different set of the data.</p><p>MongoDB supports and implements <code>auto-sharding</code> by automating balancing of data across the shards.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="mongodb-sharding-components">MongoDB Sharding Components<a class="hash-link" href="#mongodb-sharding-components" title="Direct link to heading"></a></h2><p>The first step in creating a Sharded MongoDB cluster is to understand all the components and processes that constitute a cluster</p><ul><li><strong>Query Router - mongos</strong></li></ul><p>mongos is the routing process. The goal of sharding is to make cluster of 100-1000 nodes looks like a single interface for the application and abstract all the complexity of data access from multiple shards. The mongos router is table of contents and knows where the data required by application is located, mongos forwards the application request to appropriate shard(s).</p><ul><li><strong>Config Servers</strong></li></ul><p>Config Servers hold all the metadata about which node is holding which data(chunks). mongos retrieves all the metadata from Config Servers. Config Servers are critical and its important to configure and bring the config servers first, backup config servers and setup config servers as Replica Set.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="steps-to-create-mongodb-sharded-cluster-using-docker-compose">Steps to create MongoDB Sharded Cluster using Docker Compose<a class="hash-link" href="#steps-to-create-mongodb-sharded-cluster-using-docker-compose" title="Direct link to heading"></a></h2><p>Below image show different components required to setup MongoDB sharding with Replica Set. The image also shows how application communicates to MongoDB sharded cluster. As discussed in the sharding components application always connects first to mongos and mongos communicates with config server (cfg1, cfg2, cfg3 are part of replicaset in below image)</p><div></div><p>Lets setup above MongoDB Sharding Cluster using docker compose</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-1---author-docker-compose-file">Step 1 - Author Docker Compose file<a class="hash-link" href="#step-1---author-docker-compose-file" title="Direct link to heading"></a></h3><div class="theme-admonition theme-admonition-note alert alert--secondary admonition_LlT9"><div class="admonitionHeading_tbUL"><span class="admonitionIcon_kALy"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_S0QG"><p>Ensure directory path mentioned in docker compose for persistent volume before the “:” is existing on local host</p></div></div><div class="language-YAML codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-YAML codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">services:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard1_mongo1:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard1_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard1_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo1/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo1/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo1/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo1/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20005:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard1_mongo2:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard1_mongo2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard1_mongo2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo2/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo2/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo2/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo2/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20006:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard1_mongo3:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard1_mongo3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard1_mongo3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo3/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo3/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo3/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard1_mongo3/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20007:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard2_mongo1:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard2_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard2_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo1/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo1/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo1/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo1/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20008:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard2_mongo2:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard2_mongo2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard2_mongo2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo2/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo2/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo2/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo2/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20009:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard2_mongo3:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard2_mongo3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard2_mongo3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo3/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo3/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo3/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard2_mongo3/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20010:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard3_mongo1:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard3_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard3_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo1/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo1/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo1/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo1/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20011:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard3_mongo2:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard3_mongo2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard3_mongo2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo2/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo2/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo2/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo2/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20012:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard3_mongo3:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: shard3_mongo3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: shard3_mongo3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo3/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo3/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo3/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/shard3_mongo3/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20013:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"># MongoDB Confiugration Server</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> cfg1:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: cfg1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: cfg1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg1/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg1/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg1/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg1/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20014:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> cfg2:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: cfg2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: cfg2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg2/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg2/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg2/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg2/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20015:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> cfg3:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: cfg3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: cfg3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg3/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg3/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg3/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/cfg3/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20016:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> mongos:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> image: mongo_ssh</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> hostname: mongos</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> container_name: mongos</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> volumes:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/mongos/mongod.conf:/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/mongos/initdb.d/:/docker-entrypoint-initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/mongos/data/db/:/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - ~/db/mongos/log/:/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ports:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> - 20017:27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> command: ["mongos","-f", "/etc/mongod.conf"]</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> network_mode: mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-2---draft-config-server-configuration-file-pass-clusterrole-configsvr-to-indicate-this-server-is-config-server">Step 2 - Draft Config Server configuration file (pass clusterRole: configsvr to indicate this server is Config Server)<a class="hash-link" href="#step-2---draft-config-server-configuration-file-pass-clusterrole-configsvr-to-indicate-this-server-is-config-server" title="Direct link to heading"></a></h3><div class="language-YAML codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-YAML codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">systemLog:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> destination: file</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> logAppend: true</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> path: /var/log/mongodb/mongod.log</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">storage:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> dbPath: /data/db</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> journal:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> enabled: true</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> engine: wiredTiger</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">net:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> port: 27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">sharding:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> clusterRole: configsvr</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">replication:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> replSetName: rs_config</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-3---draft-query-router-mongos-configuration-file-pass-configdbconfig-server-list">Step 3 - Draft Query Router mongos configuration file (pass configDB:config server list)<a class="hash-link" href="#step-3---draft-query-router-mongos-configuration-file-pass-configdbconfig-server-list" title="Direct link to heading"></a></h3><div class="language-YAML codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-YAML codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">systemLog:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> destination: file</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> logAppend: true</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> path: /var/log/mongodb/mongod.log</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">net:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> port: 27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">sharding:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> configDB: rs_config/cfg1:27017,cfg2:27017,cfg3:27017</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-4---copy-mongodconf-and-mongosconf-to-the-path-mentioned-in-step-1-docker-composeyaml">Step 4 - Copy mongod.conf and mongos.conf to the path mentioned in step 1 <code>docker-compose.yaml</code><a class="hash-link" href="#step-4---copy-mongodconf-and-mongosconf-to-the-path-mentioned-in-step-1-docker-composeyaml" title="Direct link to heading"></a></h3><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-5---spin-up-config-server-mongos-all-mongod-nodes">Step 5 - Spin up Config Server, mongos, all mongod nodes<a class="hash-link" href="#step-5---spin-up-config-server-mongos-all-mongod-nodes" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> compose up -d</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-6---connect-to-config-server-and-add-config-server-in-a-replica-set">Step 6 - Connect to config server and add config server in a Replica Set<a class="hash-link" href="#step-6---connect-to-config-server-and-add-config-server-in-a-replica-set" title="Direct link to heading"></a></h3><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token literal-property property" style="color:#36acaa">rs_config</span><span class="token operator" style="color:#393A34">:</span><span class="token constant" style="color:#36acaa">PRIMARY</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">initiate</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token literal-property property" style="color:#36acaa">rs_config</span><span class="token operator" style="color:#393A34">:</span><span class="token constant" style="color:#36acaa">PRIMARY</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"cfg2:27017"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token literal-property property" style="color:#36acaa">rs_config</span><span class="token operator" style="color:#393A34">:</span><span class="token constant" style="color:#36acaa">PRIMARY</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"cfg3:27017"</span><span class="token punctuation" style="color:#393A34">)</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-7----add-all-data-nodes-to-replicaset">Step 7 - Add all data nodes to replicaset<a class="hash-link" href="#step-7----add-all-data-nodes-to-replicaset" title="Direct link to heading"></a></h3><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain"># </span><span class="token maybe-class-name">Connect</span><span class="token plain"> to shard1_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">admin</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">initiate</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo1 </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> admin</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"shard1_mongo2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo1 </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> admin</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"shard1_mongo3"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"># </span><span class="token maybe-class-name">Connect</span><span class="token plain"> to shard2_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">admin</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">initiate</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo2 </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"shard2_mongo2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo2 </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"shard2_mongo3"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"># </span><span class="token maybe-class-name">Connect</span><span class="token plain"> to shard3_mongo1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">test</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">initiate</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo3 </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> other</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"shard3_mongo2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo3 </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"shard3_mongo3"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-8--connect-to-mongos-and-convert-data-replicaset-nodes-to-shards">Step 8 – Connect to mongos and convert data replicaset nodes to shards<a class="hash-link" href="#step-8--connect-to-mongos-and-convert-data-replicaset-nodes-to-shards" title="Direct link to heading"></a></h3><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain">sh</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">addShard</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"rs_mongo1/shard1_mongo1:27017,shard1_mongo2:27017,shard1_mongo3:27017"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain">sh</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">addShard</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"rs_mongo2/shard2_mongo1:27017,shard2_mongo2:27017,shard2_mongo3:27017"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain">sh</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">addShard</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">"rs_mongo3</span><span class="token operator" style="color:#393A34">/</span><span class="token plain">shard3_mongo1</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token punctuation" style="color:#393A34">,</span><span class="token literal-property property" style="color:#36acaa">shard3_mongo2</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-9--connect-to-mongos-and-enable-sharding-on-a-test-database-employee">Step 9 – Connect to mongos and enable sharding on a test database “Employee”<a class="hash-link" href="#step-9--connect-to-mongos-and-enable-sharding-on-a-test-database-employee" title="Direct link to heading"></a></h3><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">adminCommand</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">{</span><span class="token literal-property property" style="color:#36acaa">enableSharding</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"employee"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">)</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-10--generate-test-data--create-an-index-on-the-key-to-be-sharded-and-shard-the-collection">Step 10 – Generate test data ; Create an index on the key to be sharded and shard the collection<a class="hash-link" href="#step-10--generate-test-data--create-an-index-on-the-key-to-be-sharded-and-shard-the-collection" title="Direct link to heading"></a></h3><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> use employee</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">switched to db employee</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> </span><span class="token keyword control-flow" style="color:#00009f">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">var</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34"><</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">100000</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> i</span><span class="token operator" style="color:#393A34">++</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token property-access">emp_list2</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">insert</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"sr_no"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"emp # "</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> i</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"create_date"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">new</span><span class="token plain"> </span><span class="token class-name">Date</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token property-access">emp_list2</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">ensureIndex</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">{</span><span class="token string-property property" style="color:#36acaa">"sr_no"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"hashed"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> sh</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">shardCollection</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"employee.emp_list2"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token string-property property" style="color:#36acaa">"sr_no"</span><span class="token operator" style="color:#393A34">:</span><span class="token string" style="color:#e3116c">"hashed"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"collectionsharded"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"employee.emp_list2"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"collectionUUID"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token constant" style="color:#36acaa">UUID</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"17195baa-fc6c-4c3e-8a2b-58fb1278e40c"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"ok"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"operationTime"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">Timestamp</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">1633177398</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">26</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"$clusterTime"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"clusterTime"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">Timestamp</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">1633177398</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">26</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"signature"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"hash"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">BinData</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">,</span><span class="token string" style="color:#e3116c">"AAAAAAAAAAAAAAAAAAAAAAAAAAA="</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"keyId"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">NumberLong</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-11--validate-sharding-status">Step 11 – Validate sharding status<a class="hash-link" href="#step-11--validate-sharding-status" title="Direct link to heading"></a></h3><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> sh</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">status</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token operator" style="color:#393A34">--</span><span class="token operator" style="color:#393A34">-</span><span class="token plain"> </span><span class="token maybe-class-name">Sharding</span><span class="token plain"> </span><span class="token maybe-class-name">Status</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">--</span><span class="token operator" style="color:#393A34">-</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> sharding version</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"minCompatibleVersion"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">5</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"currentVersion"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">6</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"clusterId"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">ObjectId</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"6157efd7982782e314f1b651"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">shards</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo1"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"host"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo1/shard1_mongo1:27017,shard1_mongo2:27017,shard1_mongo3:27017"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"state"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo2"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"host"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo2/shard2_mongo1:27017,shard2_mongo2:27017,shard2_mongo3:27017"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"state"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo3"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"host"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo3/shard3_mongo1:27017,shard3_mongo2:27017,shard3_mongo3:27017"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"state"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> active mongoses</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"4.4.8"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">autosplit</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token maybe-class-name">Currently</span><span class="token plain"> enabled</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> yes</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">balancer</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token maybe-class-name">Currently</span><span class="token plain"> enabled</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> yes</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token maybe-class-name">Currently</span><span class="token plain"> running</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> no</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token maybe-class-name">Failed</span><span class="token plain"> balancer rounds </span><span class="token keyword" style="color:#00009f">in</span><span class="token plain"> last </span><span class="token number" style="color:#36acaa">5</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">attempts</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token maybe-class-name">Migration</span><span class="token plain"> </span><span class="token maybe-class-name">Results</span><span class="token plain"> </span><span class="token keyword control-flow" style="color:#00009f">for</span><span class="token plain"> the last </span><span class="token number" style="color:#36acaa">24</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">hours</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token number" style="color:#36acaa">682</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token maybe-class-name">Success</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">databases</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"config"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"primary"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"config"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"partitioned"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">true</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> config</span><span class="token punctuation" style="color:#393A34">.</span><span class="token property-access">system</span><span class="token punctuation" style="color:#393A34">.</span><span class="token property-access">sessions</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard key</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">unique</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">false</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">balancing</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">true</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">chunks</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs_mongo1 </span><span class="token number" style="color:#36acaa">342</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs_mongo2 </span><span class="token number" style="color:#36acaa">341</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs_mongo3 </span><span class="token number" style="color:#36acaa">341</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> too many chunks to print</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> use verbose </span><span class="token keyword control-flow" style="color:#00009f">if</span><span class="token plain"> you want to force print</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> employee</span><span class="token punctuation" style="color:#393A34">.</span><span class="token property-access">emp_list2</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> shard key</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"sr_no"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"hashed"</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">unique</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">false</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">balancing</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">true</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">chunks</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs_mongo1 </span><span class="token number" style="color:#36acaa">2</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs_mongo2 </span><span class="token number" style="color:#36acaa">2</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> rs_mongo3</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-12---validate-chunk-distribution">Step 12 - Validate chunk distribution<a class="hash-link" href="#step-12---validate-chunk-distribution" title="Direct link to heading"></a></h3><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongos</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">getSiblingDB</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"employee"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">.</span><span class="token property-access">emp_list2</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">getShardDistribution</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token maybe-class-name">Shard</span><span class="token plain"> rs_mongo1 at rs_mongo1</span><span class="token operator" style="color:#393A34">/</span><span class="token plain">shard1_mongo1</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token punctuation" style="color:#393A34">,</span><span class="token literal-property property" style="color:#36acaa">shard1_mongo2</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token punctuation" style="color:#393A34">,</span><span class="token literal-property property" style="color:#36acaa">shard1_mongo3</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">data</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">09MiB docs </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">33426</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">chunks</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> estimated data per chunk </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">04MiB</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> estimated docs per chunk </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">16713</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token maybe-class-name">Shard</span><span class="token plain"> rs_mongo3 at rs_mongo3</span><span class="token operator" style="color:#393A34">/</span><span class="token plain">shard3_mongo1</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token punctuation" style="color:#393A34">,</span><span class="token literal-property property" style="color:#36acaa">shard3_mongo2</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token punctuation" style="color:#393A34">,</span><span class="token literal-property property" style="color:#36acaa">shard3_mongo3</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">data</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">09MiB docs </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">33379</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">chunks</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> estimated data per chunk </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">04MiB</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> estimated docs per chunk </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">16689</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token maybe-class-name">Shard</span><span class="token plain"> rs_mongo2 at rs_mongo2</span><span class="token operator" style="color:#393A34">/</span><span class="token plain">shard2_mongo1</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token punctuation" style="color:#393A34">,</span><span class="token literal-property property" style="color:#36acaa">shard2_mongo2</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token punctuation" style="color:#393A34">,</span><span class="token literal-property property" style="color:#36acaa">shard2_mongo3</span><span class="token operator" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">data</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">08MiB docs </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">33195</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">chunks</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> estimated data per chunk </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">04MiB</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> estimated docs per chunk </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">16597</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token maybe-class-name">Totals</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">data</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">6</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">28MiB docs </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">100000</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">chunks</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">6</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token maybe-class-name">Shard</span><span class="token plain"> rs_mongo1 contains </span><span class="token number" style="color:#36acaa">33.42</span><span class="token operator" style="color:#393A34">%</span><span class="token plain"> data</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">33.42</span><span class="token operator" style="color:#393A34">%</span><span class="token plain"> docs </span><span class="token keyword" style="color:#00009f">in</span><span class="token plain"> cluster</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> avg obj size on shard </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> 65B</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token maybe-class-name">Shard</span><span class="token plain"> rs_mongo3 contains </span><span class="token number" style="color:#36acaa">33.37</span><span class="token operator" style="color:#393A34">%</span><span class="token plain"> data</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">33.37</span><span class="token operator" style="color:#393A34">%</span><span class="token plain"> docs </span><span class="token keyword" style="color:#00009f">in</span><span class="token plain"> cluster</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> avg obj size on shard </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> 65B</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token maybe-class-name">Shard</span><span class="token plain"> rs_mongo2 contains </span><span class="token number" style="color:#36acaa">33.19</span><span class="token operator" style="color:#393A34">%</span><span class="token plain"> data</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">33.19</span><span class="token operator" style="color:#393A34">%</span><span class="token plain"> docs </span><span class="token keyword" style="color:#00009f">in</span><span class="token plain"> cluster</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> avg</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>]]></content:encoded>
<category>mongodb</category>
<category>docker</category>
<category>sharding</category>
</item>
<item>
<title><![CDATA[MongoDB Replicaset with Persistent Volume using Docker Compose]]></title>
<link>https://ivishalgandhi.github.io/mongodb-rs-docker-persistent-volume</link>
<guid>mongodb-rs-docker-persistent-volume</guid>
<pubDate>Sat, 18 Sep 2021 00:00:00 GMT</pubDate>
<description><![CDATA[In this article we will see the steps required to create and configure MongoDB replicaset containers on persistent volumes using Docker Compose. Compose was developed to define, configure and spin-up multi-container docker applications with single command, further reducing . Extensive usage of Docker with several container management quickly becomes cumbersome, Compose overcomes this problem and allows to easily handle multiple containers at once using YAML configuration docker-compose.yml]]></description>
<content:encoded><![CDATA[<p>In this article we will see the steps required to create and configure MongoDB replicaset containers on <strong>persistent volumes</strong> using <a href="https://docs.docker.com/compose/" target="_blank" rel="noopener noreferrer">Docker Compose</a>. Compose was developed to define, configure and spin-up multi-container docker applications with single command, further reducing . Extensive usage of Docker with several container management quickly becomes cumbersome, Compose overcomes this problem and allows to easily handle multiple containers at once using YAML configuration <code>docker-compose.yml</code></p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="docker-compose-steps">Docker Compose Steps<a class="hash-link" href="#docker-compose-steps" title="Direct link to heading"></a></h2><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-1-system-configuration">Step 1: System Configuration<a class="hash-link" href="#step-1-system-configuration" title="Direct link to heading"></a></h3><p>To run Compose, make sure you have installed Compose on your local system where Docker is installed. The Compose setup and installation instructions can be found here.</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-2-ensure-mongo_net-network-bridge-is-already-existing">Step 2: Ensure mongo_net network bridge is already existing<a class="hash-link" href="#step-2-ensure-mongo_net-network-bridge-is-already-existing" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> network create mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> network inspect mongo_net </span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-3-lets-convert-the-below-command-as-seen-in-previous-blog-post-to-docker-composeyml-if-you-are-new-to-docker-and-drafting-compose-files-try-using-composerize-to-convert-docker-run-commands-into-compose-yaml-output">Step 3: Lets convert the below command as seen in previous blog post to docker-compose.yml. If you are new to Docker and drafting compose files try using composerize to convert docker run commands into compose YAML output<a class="hash-link" href="#step-3-lets-convert-the-below-command-as-seen-in-previous-blog-post-to-docker-composeyml-if-you-are-new-to-docker-and-drafting-compose-files-try-using-composerize-to-convert-docker-run-commands-into-compose-yaml-output" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> run -d -p </span><span class="token number" style="color:#36acaa">20003</span><span class="token plain">:27017 --name mongo3 --network mongo_net mongo:4.4.9-rc0 mongod --replSet rs_mongo</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>There are few additional attributes passed in the <code>docker-compose.yml</code>. The difference in the options passed in the command line above and <code>docker-compose.yml</code> is as below</p><ul><li>image: custom image uploaded to docker hub with additional utilities installed on ubuntu build
hostname: container host name</li><li>volumes: map directory on the host file system to manage and store container data. In the below YAML i use separate directory for all 3 MongoDB replicaset. This helps in creating persistent data store for docker containers and doesn’t bloat the container runtime instance.</li><li>Pass mongod configuration options through file mongod.conf</li></ul><p>Create the below YAML compose file in your favourite editor, i have been using Visual Studio Code. Save the file as docker-compose.yml</p><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ code </span><span class="token builtin class-name">.</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><div class="language-yaml codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-yaml codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic">#version: "3.3"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token key atrule" style="color:#00a4db">services</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">mongo_1</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">image</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> ivishalgandhi/mongo</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">custom</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">latest</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">hostname</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">container_name</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">volumes</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_1/mongod.conf</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_1/initdb.d/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/docker</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">entrypoint</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_1/data/db/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_1/log/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">ports</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> 20003</span><span class="token punctuation" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">command</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token string" style="color:#e3116c">"-f"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"/etc/mongod.conf"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token string" style="color:#e3116c">"--replSet"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo"</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">network_mode</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">mongo_2</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">image</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> ivishalgandhi/mongo</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">custom</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">latest</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">hostname</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">container_name</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">volumes</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_2/mongod.conf</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_2/initdb.d/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/docker</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">entrypoint</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_2/data/db/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_2/log/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">ports</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> 20004</span><span class="token punctuation" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">command</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token string" style="color:#e3116c">"-f"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"/etc/mongod.conf"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token string" style="color:#e3116c">"--replSet"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo"</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">network_mode</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">mongo_3</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">image</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> ivishalgandhi/mongo</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">custom</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">latest</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">hostname</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">container_name</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">volumes</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_3/mongod.conf</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/etc/mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_3/initdb.d/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/docker</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">entrypoint</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">initdb.d/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_3/data/db/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/data/db/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> /Users/vishalgandhi/learning/docker/mongo_replset/mongo_3/log/</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">/var/log/mongodb/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">ports</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> 20005</span><span class="token punctuation" style="color:#393A34">:</span><span class="token number" style="color:#36acaa">27017</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">command</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token string" style="color:#e3116c">"-f"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"/etc/mongod.conf"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token string" style="color:#e3116c">"--replSet"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo"</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">network_mode</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-4-create-mongodconf">Step 4: create mongod.conf<a class="hash-link" href="#step-4-create-mongodconf" title="Direct link to heading"></a></h3><div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ code .</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><div class="language-YAML codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-YAML codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain"># mongod.conf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"># for documentation of all options, see:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"># http://docs.mongodb.org/manual/reference/configuration-options/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"># where to write logging data.</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">systemLog:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> destination: file</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> logAppend: true</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> path: /var/log/mongodb/mongod.log</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"># Where and how to store data.</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">storage:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> dbPath: /data/db</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> journal:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> enabled: true</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> engine: wiredTiger</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"># network interfaces</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">net:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> port: 27017</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> bindIp: 127.0.0.1 </span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-5-spin-up-replicaset-containers">Step 5: Spin-up replicaset containers<a class="hash-link" href="#step-5-spin-up-replicaset-containers" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> compose up -d</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">+</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> Running </span><span class="token number" style="color:#36acaa">3</span><span class="token plain">/3</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ⠿ Container mongo_2 Created </span><span class="token number" style="color:#36acaa">0</span><span class="token plain">.2s</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ⠿ Container mongo_1 Created </span><span class="token number" style="color:#36acaa">0</span><span class="token plain">.2s</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ⠿ Container mongo_3 Created</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-6-initiate-replicaset">Step 6: Initiate replicaset<a class="hash-link" href="#step-6-initiate-replicaset" title="Direct link to heading"></a></h3><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> </span><span class="token builtin class-name">exec</span><span class="token plain"> -it mongo_1 </span><span class="token function" style="color:#d73a49">bash</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">root@mongo_1:/</span><span class="token comment" style="color:#999988;font-style:italic"># mongo</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo:SECONDARY</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs.initiate</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> _id: “rs_mongo”,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> version: </span><span class="token number" style="color:#36acaa">1</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> members: </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> _id: </span><span class="token number" style="color:#36acaa">0</span><span class="token plain">, </span><span class="token function" style="color:#d73a49">host</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> “mongo_1:27017” </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> _id: </span><span class="token number" style="color:#36acaa">1</span><span class="token plain">, </span><span class="token function" style="color:#d73a49">host</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> “mongo_2:27017” </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> _id: </span><span class="token number" style="color:#36acaa">2</span><span class="token plain">, </span><span class="token function" style="color:#d73a49">host</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> “mongo_3:27017” </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo:SECONDARY</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> db.</span><span class="token function-name function" style="color:#d73a49">isMaster</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"topologyVersion"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"processId"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> ObjectId</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"614615744d54c08963ef67f6"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"counter"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> NumberLong</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">6</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"hosts"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo_1:27017"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo_2:27017"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo_3:27017"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"setName"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"setVersion"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"ismaster"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> true,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"secondary"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> false,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"primary"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo_2:27017"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"me"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo_2:27017"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>]]></content:encoded>
<category>mongodb</category>
<category>docker</category>
<category>replicaset</category>
<category>persistent-volume</category>
</item>
<item>
<title><![CDATA[Create MongoDB Standalone and Replica Set containers using Docker]]></title>
<link>https://ivishalgandhi.github.io/create-mongodb-docker</link>
<guid>create-mongodb-docker</guid>
<pubDate>Sun, 12 Sep 2021 00:00:00 GMT</pubDate>
<description><![CDATA[Docker Containers offer easy setup, customization and scalability. In this article, i will walk you through how to use Docker to setup MongoDB standalone and replica set containers within minutes.]]></description>
<content:encoded><![CDATA[<p>Docker Containers offer easy setup, customization and scalability. In this article, i will walk you through how to use Docker to setup MongoDB standalone and replica set containers within minutes.</p><p>The article is divided in two parts, the first part is setting up the standalone MongoDB container and second part is setting up and grouping MongoDB containers as member of replica set with Docker.</p><p>Let’s get started.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="system-configuration">System Configuration<a class="hash-link" href="#system-configuration" title="Direct link to heading"></a></h2><p>To run this setup, Docker Engine is required to be installed on the system. Follow the official documentation to setup Docker Engine on your system.</p><div class="theme-admonition theme-admonition-caution alert alert--warning admonition_LlT9"><div class="admonitionHeading_tbUL"><span class="admonitionIcon_kALy"><svg viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path></svg></span>caution</div><div class="admonitionContent_S0QG"><p>The steps and configuration for both standalone and replica set is not to be used for production deployment. The intended use is only for setting up a environment to support learning of MongoDB.</p></div></div><h2 class="anchor anchorWithStickyNavbar_LWe7" id="standalone-mongodb-setup">Standalone MongoDB Setup<a class="hash-link" href="#standalone-mongodb-setup" title="Direct link to heading"></a></h2><ul><li>Pull the Docker MongoDB official image from Docker Hub. The following code snippet demonstrates pulling the docker MongoDB 4.4.9 release. To pull the MongoDB 5.0 latest release replace :4.4.9-rc0 with :latest tag</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> pull mongo:4.4.9-rc0 </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>To check if the the image pull from Docker Hub was successful</li></ul><div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ docker images </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">REPOSITORY TAG IMAGE ID CREATED SIZE</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongo 4.4.9-rc0 24599d6cde30 9 days ago 413MB</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">mongo latest 31299b956c79 10 days ago 642MB</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Lets start first standalone container – the below command starts MongoDB docker container with name mongo_449 in detached mode using the 4.4.9-rc0 image</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> run --name mongo_449 -d mongo:4.4.9-rc0</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>List the container status and health by executing</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> container </span><span class="token function" style="color:#d73a49">ls</span><span class="token plain"> -a</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">96e64ec525a2 24599d6cde30 </span><span class="token string" style="color:#e3116c">"docker-entrypoint.s…"</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token plain"> hours ago Up </span><span class="token number" style="color:#36acaa">33</span><span class="token plain"> minutes </span><span class="token number" style="color:#36acaa">27017</span><span class="token plain">/tcp mongo_449</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>To run a command inside the container<ul><li>docker exec: interact with containers (running/up mode)</li><li>-i : interactive STDIN open even if not attached to the container</li><li>-t: pseudo TTY</li></ul></li></ul><ul><li>Connect to MongoDB daemon</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">root@96e64ec525a2:/</span><span class="token comment" style="color:#999988;font-style:italic"># mongo</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">MongoDB shell version v4.4.9-rc0</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">connecting to: mongodb://127.0.0.1:27017/?compressors</span><span class="token operator" style="color:#393A34">=</span><span class="token plain">disabled</span><span class="token operator" style="color:#393A34">&</span><span class="token assign-left variable" style="color:#36acaa">gssapiServiceName</span><span class="token operator" style="color:#393A34">=</span><span class="token plain">mongodb</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">Implicit session: session </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"id"</span><span class="token plain"> </span><span class="token builtin class-name">:</span><span class="token plain"> UUID</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"ac624a79-908b-4580-90ae-22d0a7aee07a"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">MongoDB server version: </span><span class="token number" style="color:#36acaa">4.4</span><span class="token plain">.9-rc0</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Install utilities. The utilities ping, systemctl, sudo installed in the containers can be used for troubleshooting during the setup of Docker containers.</li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">root@96e64ec525a2:/</span><span class="token comment" style="color:#999988;font-style:italic"># apt-get install iputils-ping̵</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">root@96e64ec525a2:/</span><span class="token comment" style="color:#999988;font-style:italic"># apt-get install sudo </span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">root@96e64ec525a2:/</span><span class="token comment" style="color:#999988;font-style:italic"># apt-get install systemctl</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>This finishes the setup of standalone MongoDB Container. Now let’s look at ReplicaSet setup.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="creating-mongodb-replicaset-using-docker">Creating MongoDB ReplicaSet using Docker<a class="hash-link" href="#creating-mongodb-replicaset-using-docker" title="Direct link to heading"></a></h2><p>A replica set consists of a primary node together with two or more secondary nodes. It is recommended to group three or more nodes, with an odd number of total nodes. The primary node accepts all the write requests which are propagated synchronously or asynchronously to the secondary nodes. Below are the steps required to complete the replica set setup using Docker.</p><p>Create a new network(bridge) within Docker. The replica set containers will be mapped to the new network.</p><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> network create mongo_net</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> network inspect mongo_net </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Name"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo_net"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Id"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"e2567806642a9245436371a9b9904c71fadae969fbd11a7bb8203e07976b1b2a"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Created"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"2021-09-11T00:36:33.989688708Z"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Scope"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"local"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Driver"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"bridge"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"EnableIPv6"</span><span class="token builtin class-name">:</span><span class="token plain"> false,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"IPAM"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Driver"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"default"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Options"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Config"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Subnet"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"172.18.0.0/16"</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Gateway"</span><span class="token builtin class-name">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"172.18.0.1"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain">,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">..</span><span class="token plain">.</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">]</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Start 3 containers – Primary Secondary Secondary<ul><li>Break down of parameters docker run : start a new container<ul><li><code>-d</code> : run the container in detached mode</li><li><code>-p 20001:27017</code> publish container port to the host and bind 27017 to 20001 on the host. This is useful if connecting mongo client like mongosh to container</li><li><code>--name</code> : name of the mongo container</li><li><code>-- network</code> : connect to user created network mongo_net</li><li><code>mongo:4.4.9-rc0</code> : Docker MongoDB image</li><li><code>mongod --replSet rs_mongo</code> : run the mongod daemon and add the container to replica set name rs_mongo</li></ul></li></ul></li></ul><div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> run -d -p </span><span class="token number" style="color:#36acaa">20001</span><span class="token plain">:27017 --name mongo1 --network mongo_net mongo:4.4.9-rc0 mongod --replSet rs_mongo</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> run -d -p </span><span class="token number" style="color:#36acaa">20002</span><span class="token plain">:27017 --name mongo2 --network mongo_net mongo:4.4.9-rc0 mongod --replSet rs_mongo</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">$ </span><span class="token function" style="color:#d73a49">docker</span><span class="token plain"> run -d -p </span><span class="token number" style="color:#36acaa">20003</span><span class="token plain">:27017 --name mongo3 --network mongo_net mongo:4.4.9-rc0 mongod --replSet rs_mongo</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Set up Replica set. Connect to one of the containers and run the below commands. The container that receives the initiate will pass on the configuration to other containers assigned as members.</li></ul><div class="language-js codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-js codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test_2</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> config </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rs_mongo"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"members"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"host"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo1:27017"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"host"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo2:27017"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"_id"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string-property property" style="color:#36acaa">"host"</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"mongo3:27017"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> admin</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">initiate</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">config</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token comment" style="color:#999988;font-style:italic">//Insert test data</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> admin</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> use test_2</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test_2</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token property-access">employees</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">insert</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">{</span><span class="token literal-property property" style="color:#36acaa">name</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"vishal"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token comment" style="color:#999988;font-style:italic">//To read queries on secondary run setReadPref. </span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> secondary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test_2</span><span class="token operator" style="color:#393A34">></span><span class="token plain">db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">getMongo</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">setReadPref</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">'secondary'</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> secondary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test_2</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token property-access">employees</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">find</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">_id</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">ObjectId</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"613c99801ea796508e3c73f5"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">name</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">'vishal'</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><ul><li>Validate Replica Set Configuration</li></ul><div class="language-js codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-js codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test_2</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> db</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">printReplicationInfo</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">configured oplog size</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token string" style="color:#e3116c">'557174 MB'</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token operator" style="color:#393A34">--</span><span class="token operator" style="color:#393A34">-</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">log length start to end</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token string" style="color:#e3116c">'71372 secs (19.83 hrs)'</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token operator" style="color:#393A34">--</span><span class="token operator" style="color:#393A34">-</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">oplog first event time</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token string" style="color:#e3116c">'Sat Sep 11 2021 15:47:21 GMT+0530 (India Standard Time)'</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token operator" style="color:#393A34">--</span><span class="token operator" style="color:#393A34">-</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">oplog last event time</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token string" style="color:#e3116c">'Sun Sep 12 2021 11:36:53 GMT+0530 (India Standard Time)'</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token operator" style="color:#393A34">--</span><span class="token operator" style="color:#393A34">-</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">now</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token string" style="color:#e3116c">'Sun Sep 12 2021 11:36:54 GMT+0530 (India Standard Time)'</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">rs_mongo </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">direct</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> primary</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> test_2</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">conf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">_id</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">'rs_mongo'</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">version</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">term</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">protocolVersion</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">Long</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"1"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">writeConcernMajorityJournalDefault</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">true</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">members</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">_id</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">host</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">'mongo1:27017'</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">arbiterOnly</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">false</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">buildIndexes</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">true</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">hidden</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">false</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">priority</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">tags</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">slaveDelay</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">Long</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"0"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">votes</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">_id</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">host</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">'mongo2:27017'</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">arbiterOnly</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">false</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">buildIndexes</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">true</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">hidden</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">false</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">priority</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">tags</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">slaveDelay</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">Long</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"0"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">votes</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">_id</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">host</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">'mongo3:27017'</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">arbiterOnly</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">false</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">buildIndexes</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">true</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">hidden</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">false</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">priority</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">tags</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">slaveDelay</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token function maybe-class-name" style="color:#d73a49">Long</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"0"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">votes</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>That concludes this article.</p>]]></content:encoded>
<category>mongodb</category>
<category>containers</category>
<category>docker</category>
<category>mongo-replicaset</category>
</item>
</channel>
</rss>