CRUD Callback Documentation Incomprehensive

XMLWordPrintableJSON

    • None
    • None
    • None
    • None
    • None
    • None
    • None

      There are many methods of the Collection class that do not go into enough detail regarding the callback result.

      Consider the Collection.updateMany (doc link) method. The callback is documented to take on the form Collection~writeOpCallback (doc link) which describes the following data model:

      {
      error: MongoError
      result: Collection~WriteOpResult
      }
      

      Collection-WriteOpResult depicts the following data model:

      {
      ops: Array.<object>
      connection: object
      result: object
      }
      

      By this point, it is understood the callback arguments for Collection.updateMany are as follows:

      error: MongoError
      result:
      	ops: Array.<object>
      	connection: object
      	result: object
      

      In fact, the actual callback arguments are as follows:

      error: MongoError
      result:
      	result:
      		ok: boolean
      		nModified: integer
      		n: integer
      	connection: Server.connections()[x]
      	matchedCount: integer
      	modifiedCount: integer
      	upsertedId: object
      		index
      		_id
      	upsertedCount: integer
      

      What the documentation describes and the actual result are not completely aligned, and, worse-yet, the documentation leaves out key properties and their associated hierarchy.

      This is just one example of many. I have tested a handful of Collection methods: insert, insertOne, insertMany, remove, deleteOne, deleteMany, updateOne (with and without upsert), updateMany, update (with and without multi), findAndModify, findOneAndUpdate (with and without returnOriginal), and findOneAndDelete. All of the aforementioned methods are at least lacking the description of properties, and many of them do not align precisely with the callback and result object definitions.

      I have attached a sample script crud-ops-run.js that I used to investigate the outcome of the callbacks. I have also attached the logged output crud-ops-test.out, and my crude/psuedo-yaml representation of the result models crud-ops-structure.txt.

      The documentation for these important and often-used methods is confusing and incomplete. The examples hint towards some of the non-defined (in the formal documentation at least) properties, but they are scattered at best.

        1. crud-ops-run.js
          3 kB
        2. crud-ops-structure.txt
          1 kB
        3. crud-ops-test.out
          12 kB

              Assignee:
              Christian Amor Kvalheim
              Reporter:
              Andrew Zammit
              None
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: