Example of one document:
{
"_id":{
"quarter":{
"quarter":4,
"year":2009
},
"ticker":"MMM"
},
"data":{
"C1":2.4676424337728315,
"C10":-1.7952609553649523,
"C11":-0.024843006011523616,
"C12":19.3099694596474
}
}
So I want to get all the documents equal to year 2009 by using pymongo. Thank you
CodePudding user response:
the query to find the years is find({"_id.quarter.year": 2009})
import pymongo
client = pymongo.MongoClient("mongodb://uname:pass@ip:port/") ##update your Atlas DB connection details
db = client.simple ##Replace <simple> with your atlas db name
years = db.cars ##Replace <cars> with the Collection name
requests = years.find({"_id.quarter.year": 2009}) ##This returns an object
##to print out the documents in the requests object
for doc in requests:
print(doc)