I'm using size on a nested array:
totalRevisions: { $size: `$revisions.${entryId}.${languageId}` }
However before a revision is made this path won't exist. How can I prevent Mongo from throwing an exception "MongoError: The argument to $size must be an array, but was of type: missing" and return 0
for totalRevisions
instead? Thanks.
Data structure:
project: {
...
revisions: {
<entryId1>: {
<languageId1>: [revision, revision, ...],
<languageId2>: [revision, revision, ...],
..more langs..
},
..more entries..
}
}