Skip to content

A Repository created to describe the usage of pymongo a Python-MongoDB driver to connect, insert, select, update and delete Documents with MongoDB database.

License

Notifications You must be signed in to change notification settings

k-arthik-r/Pymongo_Introduction

Repository files navigation

Pymongo Introduction

     

A Repository created to describe the usage of pymongo a Python-MongoDB driver to connect, insert, select, update and delete Documents with MongoDB database.


Installation

Install pymongo using pip

  pip install pymongo

Or visit Here For Manual Download


Requirements

  • Python 3.11
  • MongoDB 4.0.4 - Database Server
  • (Optional)MongoDB Compass 1.16.3 - To view database

Imports

Import the package

  import pymongo

Making a Connection with MongoClient

The first step when working with PyMongo is to create a MongoClient to the running mongod instance. Doing so is easy:

from pymongo import MongoClient
client = MongoClient()

The above code will connect on the default host and port. We can also specify the host and port explicitly, as follows:

client = MongoClient('localhost', 27017)

Or use the MongoDB URI format:

client = MongoClient('mongodb://localhost:27017/')

Getting a Database

A single instance of MongoDB can support multiple independent databases. When working with PyMongo you access databases using attribute style access on MongoClient instances:

db = client.test_database

If your database name is such that using attribute style access won’t work (like test-database), you can use dictionary style access instead:

db = client['test-database']

Getting a Collection

A collection is a group of documents stored in MongoDB, and can be thought of as roughly the equivalent of a table in a relational database. Getting a collection in PyMongo works the same as getting a database:

collection = db.test_collection

or (using dictionary style access):

collection = db['test-collection']

An important note about collections (and databases) in MongoDB is that they are created lazily - none of the above commands have actually performed any operations on the MongoDB server. Collections and databases are created when the first document is inserted into them.


Getting started MongoDB Atlas

MongoDB Atlas is a fully-managed cloud database that handles all the complexity of deploying, managing, and healing your deployments on the cloud service provider of your choice (AWS , Azure, and GCP). MongoDB Atlas is the best way to deploy, run, and scale MongoDB in the cloud.

Access the file here to get started with MongoDB atlas Here


Query Code


Database

Screenshot (107)

Screenshot (108)


License

Licence


Feedback

If you have any feedback, please reach out to us at voidex.developer@gmail.com

About

A Repository created to describe the usage of pymongo a Python-MongoDB driver to connect, insert, select, update and delete Documents with MongoDB database.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages