I am trying to fetch data from MongoDB collection and return fetched data to calling function. Code is as follows.
client = pymongo.MongoClient("mongodb://localhost:27017")
db = client["DBName"]
def check(request):
data = getData(2500, "2023-03-20")
print(data)
for d in data:
print()
print(d)
return render(request, 'backtest.html')
def getData(value, somedate):
collection = db[constantsCollection.NameData]
query = {"$and": [{"value" : value}, {"datetime" : {"$regex" : somedate}}]}
data = collection.find(query)
return data
This code is giving error as AttributeError: 'Cursor' object has no attribute 'get'
Cursor is holding approx 10000 records.
I saw couple of answers but all are printing value in same function which works fine. (eg. Python MongoDB : 'Cursor' object has no attribute 'name') Looking for how to return value to calling function.
Thanks for help in advance.
Traceback :
Traceback (most recent call last): File "C:\Users\user\Envs\test\lib\site-packages\django\core\handlers\exception.py", line 56, in inner response = get_response(request) File "C:\Users\user\Envs\test\lib\site-packages\django\utils\deprecation.py", line 138, in call response = self.process_response(request, response) File "C:\Users\user\Envs\test\lib\site-packages\django\middleware\clickjacking.py", line 27, in process_response if response.get("X-Frame-Options") is not None: AttributeError: 'Cursor' object has no attribute 'get'
.get(). Then again, you're not showinggetocdatafrommongo.