In Python, we can use PyMongo, the official MongoDB Python driver, to interact with MongoDB. Below is a simple guideline on how to use MongoDB with Python:
1. Before you start, you need to make sure MongoDB is installed and running on your machine. You can download MongoDB from the official website.
1. Install pymongo – Python MongoDB driver. You can install it using pip:
```
pip install pymongo
```
1. After the installation is completed, you can import pymongo in python to start using it:
```
import pymongo
```
1. Now, make a connection to MongoDB:
```
from pymongo import MongoClient
client = MongoClient()
```
By default, MongoClient will connect to the MongoDB instance running on localhost on port 27017. If you have MongoDB running on a different host or port, you can provide the host and port to MongoClient.
1. After making the connection, you can access the database:
```
db = client.my_database #replace ‘my_database’ with your database name
```
1. Now, you should select a collection. In MongoDB, a collection is similar to a table in RDBMS:
```
collection = db.my_collection #replace ‘my_collection’ with your collection name
```
1. After you have a collection object, you can insert, find, update, remove documents (similar to records in RDBMS):
- To insert a document into a collection:
```
doc = {“name”: “John”, “age”: 30, “city”: “New York”}
collection.insert_one(doc)
```
- To find documents in a collection:
```
results = collection.find() #returns all documents
for r in results:
print®
```
- To update a document in a collection:
```
collection.update_one({“name”: “John”}, {“$set”: {“city”: “Chicago”}})
```
- To remove a document from a collection:
```
collection.delete_one({“name”: “John”})
```
- To count the number of documents in a collection:
```
count = collection.count_documents({})
print(count)
```
Remember, MongoDB stores data in a binary JSON format (BSON), and pymongo automatically converts BSON to Python dictionary when you query documents.
This is a very simple guideline. PyMongo provides many other functions to work with MongoDB. Refer to the PyMongo documentation for a complete list and detail, or use the help() function in Python.