Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1853

Empty projections should return the entire document not just the _id



    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 3.8
    • 4.0
    • Query Operations
    • None
    • Major Change


      Etienne Pelletier's recent PR brought to light a discrepancy in how PyMongo behaves vis-a-vis the Mongo shell when it comes to dealing with empty projection dictionaries--while PyMongo replaces them with {'_id': 1}, the shell simply forwards them to the server which in turn returns all document fields (i.e. it behaves as it would if no projection had been passed).

      Both behaviors seem to hold some merit--an empty projection could indicate that the user wants NO fields, in which case, PyMongo's use of {'_id': 1} as the projection document does make sense. On the other hand, in doing this replacement of the projection document we end up in conflict with the behavior of the shell, as well as that of the DB command itself (which returns all document fields when it encounters an empty projection).

      The CRUD spec does not say how drivers should handle empty projection dictionaries. It only says that drivers should not forward any value for projection if the user has not provided one.

      We should do a survey of how other drivers handle empty projection dictionaries while deciding whether to accept the proposed change or keep the current behavior.
      Additionally, we might want to amend the CRUD specification to ensure uniformity across drivers when dealing with empty projection documents.


        Issue Links



              julius.park@mongodb.com Julius Park
              prashant.mital Prashant Mital (Inactive)
              0 Vote for this issue
              4 Start watching this issue