I have come across some issues that I think are worth sharing. This is in regards to serializing and subsequently querying arrays of documents using mongodb in Juju and specifically using mgo/txn.
There are two main points that I would like to highlight here and these are:
- The base capabilities of mongodb available to a developer who is hacking on Juju.
- The identification and update of a particular document in an array using mgo/txn.
The base capabilities of mongodb available to a developer when hacking on Juju
Currently, with Bionic and Cosmic, Juju is using the package mongodb-server-core which is at mongodb version 3.6. This (and subsequent post mongo 3.2 versions) add features that help with the manipulation of nested document arrays. For example, 3.6 adds the all positions operator ($). However, using the ($) operator will cause tests that run against versions of mongodb prior to 3.6 to fail. Must we use only those capabilities found in the mongodb version used by the earliest supported version of Juju? If so, is this constraint documented anywhere?
The identification and update of a particular document in an array using mgo/txn
Basically, how does one use the ($) operator with mgo/txn? According to the mongo docs if a user wants to select an item from a document array on which to operate with the ($) operator the user must match an element of a nested array with a query that is grouped with the id of the parent document. Yet, you cannot do this with mgo/txn, the transaction ID field does not allow it, an error occurs if you try this. I cannot easily web search a solution.
I have searched the Juju code base only to find that nested document arrays are seldom used. Is this due to difficulties with the mgo/txn package and the version of Juju as stated above?