I have a simple pipeline and running fine in MongoDB Compass, but the same pipeline when I try to execute using Pymongo I got less number of documents. When I checked the result cursor is having or limiting only the 100 documents, but in Compass I see more data returned. I am using the below connection but not sure what I am missing.
The expected documents less than 200 documents.
Python version: 3.7
Pymongo version: pymongo==3.11.3
db.collections.aggregate([
{
'$match': {
'subject': {
'$in': [
'1','2','3'
]
}
}
}, {
'$lookup': {
'from': 'schools',
'localField': 'locId',
'foreignField': 'locId',
'as': 'schools'
}
}, {
'$unwind': {
'path': '$schools',
'preserveNullAndEmptyArrays': True
}
}, {
'$unwind': {
'path': '$schools.schools',
'preserveNullAndEmptyArrays': False
}
}, {
'$match': {
'schools.appointmentDate': {
'$gte': datetime(2021, 3, 15, 0, 0, 0, tzinfo=timezone.utc),
'$lt': datetime(2021, 3, 16, 0, 0, 0, tzinfo=timezone.utc)
},
'schools.schools.appointmentStatus': {
'$in': [
'Scheduled'
]
}
}
}, {
'$group': {
'_id': '$subject',
'totalAppointments': {
'$sum': 1
}
}
}
])
I have also used {"$limit" : 10000}
after the sort as well in the mongo query, but not helping me.
Can some one please help me what I have to check?
Thanks