Python을 이용한 간단한 mongodb insert 예제
1. easy_install.exe를 이용하여, mongodb python driver인 pymongo를 설치
2. 코드 작성
connection얻고, db선택하고,collection(여기서는 users테이블) 선택하면되고,
insert,update등은 기존 mongodb script와 유사함. 에러 처리는 아래와 같이 try,except 사용
import sys import pymongo
connection = pymongo.MongoClient("mongodb://localhost") db = connection.terrydb users = db.users
doc = {'_id':'myid','firstname':'Terry','lastname':'Cho'}
try: users.insert(doc) except: print "insert failed",sys.exc_info()[0]
|
3. insert 확인
'클라우드 컴퓨팅 & NoSQL > MongoDB' 카테고리의 다른 글
MultiThread로 RabbitMQ에서 메세지를 읽어서 MongoDB에 쓰는 예제 (Python) (1) | 2014.01.03 |
---|---|
mongodb locking (0) | 2014.01.02 |
MongoDB의 Physical 데이타 저장 구조 (4) | 2013.05.03 |
MongoDB 30분만에 이해하기.. (설치,테스트 및 자바 샘플) (3) | 2013.04.30 |
MongoDB vs Cassandra Performance (3) | 2012.03.05 |