Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 078e01b

Browse files
Update README.md
1 parent e90b176 commit 078e01b

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

‎README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# mongodb-with-python-tutorial
22
MongoDB with Pymongo Tutorial
33

4-
### Installing
4+
### MongoDB Server
5+
6+
Run a mongodb server with docker:
7+
8+
```
9+
$ docker run --rm -itd --name mongodb -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=password -p 27017:27017 mongo:4.4
10+
```
11+
12+
### Python Package
13+
14+
Install the python package to interact with mongodb using python:
515

616
```
717
$ pip install pymongo
@@ -13,38 +23,36 @@ Making a connection without authentication:
1323

1424
```
1525
>>> from pymongo import MongoClient
16-
>>> uri = 'mongodb://mongodb.domain.com:27017/'
26+
>>> uri = 'mongodb://localhost:27017/'
1727
>>> client = MongoClient(uri)
1828
>>> client.database_names()
19-
[u'admin', u'local', u'mycargarage', u'random_api', u'shared_db', u'testdb']
29+
['admin', 'config', 'local']
2030
```
2131

2232
Making a connection with authentication:
2333

2434
```
2535
>>> from pymongo import MongoClient
26-
>>> uri = 'mongodb://username:password@mongodb.domain.com:27017/random_api?authSource=admin&authMechanism=SCRAM-SHA-1'
36+
>>> uri = 'mongodb://root:password@localhost:27017/admin?authSource=admin&authMechanism=SCRAM-SHA-1'
2737
>>> client = MongoClient(uri)
2838
>>> client.database_names()
29-
[u'admin', u'local', u'mycargarage', u'random_api', u'shared_db', u'testdb']
39+
['admin', 'config', 'local']
3040
```
3141

3242
### Listing Databases
3343

3444

3545
```
36-
>>> client = MongoClient(uri)
3746
>>> client.database_names()
38-
[u'admin', u'local', u'mycargarage', u'random_api', u'shared_db', u'testdb']
47+
['admin', 'config', 'local']
3948
```
4049

4150
### Listing Collections
4251

4352
```
44-
>>> client = MongoClient(uri)
45-
>>> db = client.shared_db
46-
>>> db.collection_names()
47-
[u'flask_reminders', u'test', u'usersessions', u'messages']
53+
>>> db = client.config
54+
>>> db.list_collection_names()
55+
['system.sessions']
4856
```
4957

5058
### Write One Document
@@ -71,8 +79,8 @@ ObjectId('5cad16a5a5f3826f6f046d74')
7179
We can verify that the collection is present:
7280

7381
```
74-
>>> db.collection_names()
75-
[u'transactions']
82+
>>> db.list_collection_names()
83+
['transactions']
7684
```
7785

7886
### Write Many Documents
@@ -343,7 +351,6 @@ MongoClient(host=['mongodb.domain.com:27017'], document_class=dict, tz_aware=Fal
343351
name = StringField(required=True, max_length=200)
344352
city = StringField(required=True, max_length=200)
345353
can_code = BooleanField(required=True)
346-
347354
```
348355

349356
Create a student:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /