def day():
message ="one day is remaining to take up your food"
nextday =datetime.now() + timedelta(days= 1)
nextdaydate= nextday.strftime('X%d/X%m/%Y').replace('X0','X').replace('X','')
bookingdata =db.booking.find({"$and":[{'date':nextdaydate},{'status':'confirmed'}]})
for data in bookingdata:
user=db.users.find_one({'_id' : data["user"]},{"devicetoken":1})
booking_id=data["_id"]
sendremindpush(user["devicetoken"],str(booking_id),str(message))
here i'm doing cron job and want to send push notification. so i need to use two collections for that.
bookingdata =db.booking.find({"$and":[{'date':nextdaydate},{'status':'confirmed'}]})
in this line i get date from booking and
user=db.users.find_one({'_id' : data["user"]},{"devicetoken":1})
in this line within for loop i'm getting user who booked that booking then next
booking_id=data["_id"]
in this line of the loop i'm getting booking id from above used booking collection. all are working but it's slow. i don't like this. i want reduce these two collections finding steps. i tried so many ways i can't able to optimize those two lines. is there any solution to reduce these ?