[Python] MongoDB count_documents() returns 19 but find() returns empty list - Replica Set...

Discussão em 'Python' iniciado por Stack, Maio 31, 2025.

  1. Stack

    Stack Membro Participativo

    Good morning everyone,

    I'm experiencing a consistency issue with MongoDB in production. I have a 3-node replica set deployed on OVH, and sometimes count_documents() and find() return different results for the exact same query. This issue happens always whene there are write operations on the mongo, but I doubt it could be normal.. reading and writing operations should stay consistent.

    Example:

    collection.count_documents(query) returns 19 list(collection.find(query)) returns [] (empty list)

    This happens sporadically in production with the same query executed within seconds of each other.

    • MongoDB Version: 6.0.23
    • Driver: PyMongo (Python) Version 4.8.0
    • Deployment: 3-node replica set on OVH
    • Query: Same filter used for both operations

    What I've Tried

    • Verified the query is identical in both operations
    • The issue occurs randomly, not consistently
    • I tried writeConcern "majority" + readConcern "majority"
    • Boths operations are executed inside the same session & transaction

    Continue reading...

Compartilhe esta Página