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
위 포스팅에 이어서 계속 작성합니다.
find_one
find_one은 collection에서 가장 첫 번째 데이터를 찾아주는 것이네요.
이전 포스팅에서 insert, remove를 수행해서, 현재 collection에는 0~90까지의 값을 가지는 student_id 데이터가 들어가 있는 상황입니다.
find_one 소스는 아래와 같습니다.
#!/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})
doc = collection.find_one()
print doc
간단하게 find_one 사용하는 소스와 결과를 정리해봤습니다.
'파이썬(python2.7) > 라이브러리,SW' 카테고리의 다른 글
MongoDB - db drop (데이터베이스 삭제) (1) | 2014.09.01 |
---|---|
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 |
안녕하세요 블로거님
블로거님의 MongoDB 튜토리얼을 01~05까지 연습해보면서 한가지 궁금한 점이 생겨 글 남깁니다.
collection.find_one()함수를 이용할 때 '0'번쨰 데이터 말고
원하는 위치의 데이터를 찾아낼 수 도 있는 건가요?
초급자여서 기초적인 질문 드리네요 ㅠ
https://docs.mongodb.com/manual/reference/method/db.collection.findOne/
http://api.mongodb.com/python/current/api/pymongo/collection.html?highlight=find_one#pymongo.collection.Collection.find_one
위 문서를 참고하시면 도움이 될 것 같습니다.
python을 통해서 몽고db를 사용하신다면 2번째 웹페이지를 확인해주세요.
저도 예전에 써보고 잘 안써서 답변을 드리기가 어렵네요. ㅠㅠㅠㅠ