🔥 필드값 범위로 출력 : 논리연산자 사용하기(nor)
🔥 포함여부로 출력 : in 과 nin
🔥 skip()과 limit()
🔥 리스트(list) 형태의 value값을 대상으로 검색
🔥 정규 표현식으로 부분 문자열 검색
{ '$nor': [{'흥행지수': {'$gt':10000}}, {'흥행지수': {"$lt":1000}}] }
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find( { '$nor': [{'흥행지수': {'$gt':10000}}, {'흥행지수': {"$lt":1000}}] }, {'배우이름':1,'흥행지수':1,'_id':0} ) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({ '흥행지수' : {"$in" : [5674, 9702, 5463]}}, {'배우이름':1,'흥행지수':1,'_id':0} ) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({ '흥행지수' : {"$nin" : [5674, 9702, 5463]}}, {'배우이름':1,'흥행지수':1,'_id':0} ).limit(10) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({ '$nor': [{'흥행지수': {'$gt':10000}}, {'흥행지수': {"nin":[ 9182, 8439 ]}}] }, {'배우이름':1,'흥행지수':1,'_id':0} ).limit(3) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({'흥행지수':{'$gte':10000}}).limit(10) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({'흥행지수':{'$gte':10000}}).limit(10).skip(5) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({'출연영화':{'$all':['신세계', '사바하']}}) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({'출연영화.1':'신세계'}) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({'출연영화':{'$size':5}}) for doc in docs: print(doc)
✍🏻 python
import pymongo # mongodb connection conn = pymongo.MongoClient() # pymongo로 mongodb 연결(localhost:27017) actor_db = conn.cine21 actor_collection = actor_db.actor_collection docs = actor_collection.find({'출연영화':{'$regex':'다만'}}) for doc in docs: print(doc)