@HUDSON_REYREY/

Getting Started With PyMongo: Introduction And Setup

Python

No description

fork
loading
Files
  • main.py
main.py
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
# MongoDB Setup
# Download installation from MongoDB's website:
# https://www.mongodb.com/download-center#community

# Homebrew Python Package
# https://docs.brew.sh/Homebrew-and-Python.html

# You have to then install it in Python itself by using the "brew" package to install it
# Type this in Python terminal:
# brew install mongodb 

# Once installed, type this into the Python terminal to start MongoDB:
# brew services start mongodb 

# Access your local host in Python terminal:
#curl http://localhost:27017

# Now install PyMongo through pip3 in Python terminal:
# pip3 install pymongo 

# For further help with PyMongo, refer to the documentation: 
# api.mongodb.com/python/current/api 

import pymongo 

from pymongo import MongoClient

# Create a MongoDB client object:
client = MongoClient()

# Create a MongoDB client object using default localhost parameter, and port number
# This is done by default
client2 = MongoClient('localhost', 27017)

# Mongo URL: specific URL that Mongo can use to connect to a specific machine
client3 = MongoClient('mongodb://localhost:27017/')

# Create database:
db = client.pytests