Looking at the code, the description of the modelEntityRefs document is:
type modelEntityRefsDoc struct {
UUID string `bson:"_id"`
// Machines contains the names of the top-level machines in the model.
Machines []string `bson:"machines"`
// Applications contains the names of the applications in the model.
Applications []string `bson:"applications"`
// Volumes contains the IDs of the volumes in the model.
Volumes []string `bson:"volumes"`
// Filesystems contains the IDs of the filesystems in the model.
Filesystems []string `bson:"filesystems"`
}
However, there is no reference in 'upgrades/' to 'volumes' or 'filesystems' that would be adding those values to the documents in the database. Nor is there any reference to 'modelEntityRefs' in upgrades.
And I can confirm that "{$size: 0}" does *not* match non-existent members.
So I think we just have models that have existed before Andrew's change (6e00efc) in 2016-12 that introduced the fields. (It appears to have been introduced in Juju 2.2 so the model would have been created w juju 2.1).
It seems we have a couple possible fixes:
a) Introduce an upgrade step that adds the arrays
b) Change the cleanup code from:
{"machines", bson.D{{"$size", 0}}},
{"applications", bson.D{{"$size", 0}}},
{"volumes", bson.D{{"$size", 0}}},
{"filesystems", bson.D{{"$size", 0}}},
or possibly:
{"machines", bson.D{{"$size", 0}}},
{"applications", bson.D{{"$size", 0}}},
{"$or", bson.D{{bson.M{"volumes": bson.M{"$size": 0}}},
...
Forgive the formatting, as I'm just typing this here without trying to be precise.
The DB query would look something like:
db.modelEntityRefs.find({ $or: [ { "volumes": { $exists: false}}, { "volumes": {$size: 0}}]})
an object with an array of objects is clumsy to type in bson.D objects.
An upgrade step means we don't have to worry about them being different in future versions, a change to the query makes it easier to be compatible. (It feels a little odd to add an upgrade step in 2.5.2 for a data change in 2.2.0).
Looking at the code, the description of the modelEntityRefs document is:
type modelEntityRefsDoc struct {
UUID string `bson:"_id"`
// Machines contains the names of the top-level machines in the model.
Machines []string `bson:"machines"`
// Applications contains the names of the applications in the model. applications" `
Applications []string `bson:"
// Volumes contains the IDs of the volumes in the model.
Volumes []string `bson:"volumes"`
// Filesystems contains the IDs of the filesystems in the model. filesystems" `
Filesystems []string `bson:"
}
However, there is no reference in 'upgrades/' to 'volumes' or 'filesystems' that would be adding those values to the documents in the database. Nor is there any reference to 'modelEntityRefs' in upgrades.
And I can confirm that "{$size: 0}" does *not* match non-existent members.
So I think we just have models that have existed before Andrew's change (6e00efc) in 2016-12 that introduced the fields. (It appears to have been introduced in Juju 2.2 so the model would have been created w juju 2.1).
It seems we have a couple possible fixes:
a) Introduce an upgrade step that adds the arrays
b) Change the cleanup code from:
{"machines", bson.D{{"$size", 0}}},
{"applications", bson.D{{"$size", 0}}},
{"volumes", bson.D{{"$size", 0}}},
{"filesystems", bson.D{{"$size", 0}}},
to something like: {"filesystems" , bson.D{{"$size", 0}}}, bson.D{ {"filesystems" , bson.D{{"$exists", false}}}},
{"machines", bson.D{{"$size", 0}}},
{"applications", bson.D{{"$size", 0}}},
{"$or", bson.D{{"volumes", bson.D{{"$size", 0}}}, bson.D{{"volumes", bson.D{{"$exists", false}}}},
{"$or", bson.D{
or possibly: {bson.M{ "volumes" : bson.M{"$size": 0}}}, efs.find( { $or: [ { "volumes": { $exists: false}}, { "volumes": {$size: 0}}]})
{"machines", bson.D{{"$size", 0}}},
{"applications", bson.D{{"$size", 0}}},
{"$or", bson.D{
...
Forgive the formatting, as I'm just typing this here without trying to be precise.
The DB query would look something like:
db.modelEntityR
an object with an array of objects is clumsy to type in bson.D objects.
An upgrade step means we don't have to worry about them being different in future versions, a change to the query makes it easier to be compatible. (It feels a little odd to add an upgrade step in 2.5.2 for a data change in 2.2.0).