Python - MongoDB 활용 001 (커넥션, Insert) : http://ngee.tistory.com/335
Python - MongoDB 활용 002 (update, collection list) : http://ngee.tistory.com/336
Python - MongoDB 활용 003 (find) : http://ngee.tistory.com/339
Python - MongoDB 활용 004 (remove) : http://ngee.tistory.com/340 현재 포스팅
Python - MongoDB 활용 005 (find_one) : http://ngee.tistory.com/344
위 포스팅에 이어서 계속 작성합니다.
remove
remove 함수는 원하는 데이터를 지워주는 역할이죠.
이전 포스팅에서 student_id를 for문 돌려서 0~99까지 입력했습니다.
remove에서는 student_id가 90이상인 것을 지우는 소스로 테스트를 해보겠습니다.
#!/usr/bin/python
import pymongo
connection = pymongo.MongoClient("localhost", 27017)
db = connection.testDB
collection = db.student
#for i in range(0, 100):
# collection.insert({"student_id":i})
collection.remove({"student_id": {"$gt":90}})
$gt에 대해서는 이전 포스팅에서 사용했던 것이죠.
greater than의 의미입니다.
결국 위 remove 함수가 실행되면, 데이터베이스에는 아래와 같이 데이터가 들어가 있는 상태가 될 것입니다.
.......
.......
{u'student_id': 72, u'_id': ObjectId('536a82d2ae3e83310b13199d')}
{u'student_id': 73, u'_id': ObjectId('536a82d2ae3e83310b13199e')}
{u'student_id': 74, u'_id': ObjectId('536a82d2ae3e83310b13199f')}
{u'student_id': 75, u'_id': ObjectId('536a82d2ae3e83310b1319a0')}
{u'student_id': 76, u'_id': ObjectId('536a82d2ae3e83310b1319a1')}
{u'student_id': 77, u'_id': ObjectId('536a82d2ae3e83310b1319a2')}
{u'student_id': 78, u'_id': ObjectId('536a82d2ae3e83310b1319a3')}
{u'student_id': 79, u'_id': ObjectId('536a82d2ae3e83310b1319a4')}
{u'student_id': 80, u'_id': ObjectId('536a82d2ae3e83310b1319a5')}
{u'student_id': 81, u'_id': ObjectId('536a82d2ae3e83310b1319a6')}
{u'student_id': 82, u'_id': ObjectId('536a82d2ae3e83310b1319a7')}
{u'student_id': 83, u'_id': ObjectId('536a82d2ae3e83310b1319a8')}
{u'student_id': 84, u'_id': ObjectId('536a82d2ae3e83310b1319a9')}
{u'student_id': 85, u'_id': ObjectId('536a82d2ae3e83310b1319aa')}
{u'student_id': 86, u'_id': ObjectId('536a82d2ae3e83310b1319ab')}
{u'student_id': 87, u'_id': ObjectId('536a82d2ae3e83310b1319ac')}
{u'student_id': 88, u'_id': ObjectId('536a82d2ae3e83310b1319ad')}
{u'student_id': 89, u'_id': ObjectId('536a82d2ae3e83310b1319ae')}
{u'student_id': 90, u'_id': ObjectId('536a82d2ae3e83310b1319af')}
이번 포스팅까지 해서, PyMongo에서 사용되는 연결, 입력, 업데이트, 검색, 삭제 정도를
정말 간단하게만 정리해봤습니다.
PyMongo에 대해서 더 확인해보고, 사용해보고자 하시는 분께서는 PyMongo 문서를 확인해보시길 바랍니다.
'파이썬(python2.7) > 라이브러리,SW' 카테고리의 다른 글
MongoDB 외부에서 접근 가능하도록 설정 (5) | 2014.07.08 |
---|---|
MongoDB GUI - robomongo (0) | 2014.05.10 |
Python - MongoDB 활용 005 (find_one) (2) | 2014.05.10 |
Python - MongoDB 활용 004 (remove) (0) | 2014.05.08 |
Python - MongoDB 활용 003 (find) (0) | 2014.05.08 |
Python - MongoDB 활용 002 (update, collection list) (0) | 2014.05.06 |
Python - MongoDB 활용 001 (커넥션, Insert) (0) | 2014.05.06 |
RabbitMQ - MQTT Plugin 문제 (2) | 2014.05.06 |