Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering MongoDB 6.x

You're reading from   Mastering MongoDB 6.x Expert techniques to run high-volume and fault-tolerant database solutions using MongoDB 6.x

Arrow left icon
Product type Paperback
Published in Aug 2022
Publisher Packt
ISBN-13 9781803243863
Length 460 pages
Edition 3rd Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Alex Giamas Alex Giamas
Author Profile Icon Alex Giamas
Alex Giamas
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Part 1 – Basic MongoDB – Design Goals and Architecture
2. Chapter 1: MongoDB – A Database for the Modern Web FREE CHAPTER 3. Chapter 2: Schema Design and Data Modeling 4. Part 2 – Querying Effectively
5. Chapter 3: MongoDB CRUD Operations 6. Chapter 4: Auditing 7. Chapter 5: Advanced Querying 8. Chapter 6: Multi-Document ACID Transactions 9. Chapter 7: Aggregation 10. Chapter 8: Indexing 11. Part 3 – Administration and Data Management
12. Chapter 9: Monitoring, Backup, and Security 13. Chapter 10: Managing Storage Engines 14. Chapter 11: MongoDB Tooling 15. Chapter 12: Harnessing Big Data with MongoDB 16. Part 4 – Scaling and High Availability
17. Chapter 13: Mastering Replication 18. Chapter 14: Mastering Sharding 19. Chapter 15: Fault Tolerance and High Availability 20. Index 21. Other Books You May Enjoy

Connecting to MongoDB

There are two ways to connect to MongoDB. The first is by using the driver for your programming language. The second is by using an ODM layer to map your model objects to MongoDB in a transparent way. In this section, we will cover both ways, using three of the most popular languages for web application development: Ruby, Python, and PHP.

Connecting using Ruby

Ruby was one of the first languages to have support from MongoDB with an official driver. The official MongoDB Ruby driver on GitHub is the recommended way to connect to a MongoDB instance. Perform the following steps to connect MongoDB using Ruby:

  1. Installation is as simple as adding it to the Gemfile, as shown in the following example:
    gem 'mongo', '~> 2.17'
  2. Then, in our class, we can connect to a database, as shown in the following example:
    require 'mongo'
    client = Mongo::Client.new([ '127.0.0.1:27017' ], database: 'test')
  3. This is...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image