Skip to content

Commit b122b56

Browse files
author
effy
committed
pymongo readme.md added for task 0003
1 parent b52f309 commit b122b56

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

effy/0003/readme.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
##mongoDB connect with python
2+
3+
###Pre-request:
4+
1. Has mongo installed and running.
5+
2. Has pymongo instaled with pip
6+
7+
###To connect
8+
```python
9+
from pymongo import MongoClient
10+
c = MongoClient()
11+
```
12+
That's it! dead simple -- but you may need to make sure that mongo is **running on the default port-- 27017**
13+
14+
python和mongo的连接出乎意料的简单。
15+
16+
需要的只是一个pymongo中的MongoClient来建立一个live connection!而且最赞的是,由于是nosql,根本不需考虑collection已有的数据是什么类型,key,schema什么的,直接统统insert。之前和relational sql连接的时候(postgres)则需要考虑原来的table里面的PK有没有重复,id是否要被maintain成incremental,之类的问题~炒鸡方便!
17+
18+
### To manipulate mongodb within python
19+
1. to access specific database
20+
21+
```python
22+
db = c['effy_db']
23+
```
24+
2. to access specific collection
25+
26+
```python
27+
cl = db['effy_collection']
28+
```
29+
db, collection acts like a **dict** in python! it actually is. When a live connection is established, *database object* becomes a dictionary with key equals to its name and value equals the object itself.
30+
31+
To access mongo shell command for absolute beginners, see <a href=http://effyhuang.com/2014/12/06/mongo-db-command-ref/> the blog</a>.

effy/0003/readme.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)