In [1]:
from pymongo import MongoClient
client = MongoClient(
"mongodb.fastcamp.us",
)
In [2]:
db = client["dobestan"]
In [3]:
collection = db["zigbang"]
In [4]:
assert collection.count() > 0
In [5]:
# 보증금이 1000만원인 매물 리스트 가져오기
collection.find({"item.deposit": 1000}).count()
for data in collection.find({"item.deposit": 1000}):
print((data.get('item').get('deposit'), data.get('item').get('rent')))
In [6]:
# 보증금이 1000만원 이상인 매물 리스트 가져오기
collection.find({"item.deposit": {'$gte': 1000}}).count()
for data in collection.find({"item.deposit": {'$gte': 1000}}):
print((data.get('item').get('deposit'), data.get('item').get('rent')))
In [7]:
# 보증금이 1000만원 이상이면서,
# 월세가 50만원 이하인 매물 가져오기
items = collection.find({
"item.deposit": {
'$gte': 1000,
},
"item.rent": {
'$lte': 50,
}
})
for item in items:
print((item.get('item').get('deposit'), item.get('item').get('rent')))
In [8]:
for item in collection.find({
"item.address1": {
'$regex': "강동구",
}
}):
print(item.get('item').get('address1'))