Hi @johan_potgieter -
Regarding your array question, assuming the two arrays you want to subtract from each other are in different fields in the same document, you could use the following approach:
chartsMonoRepl:PRIMARY> db.arraydiff.find()
{ "_id" : ObjectId("5eefd7841994dbe8050da7b8"), "a" : [ 10, 20, 30, 40, 50 ], "b" : [ 1, 2, 3, 4, 5 ] }
chartsMonoRepl:PRIMARY> db.arraydiff.aggregate([
... {
... $addFields: {
... diff: {
... $map: {
... input: {
... $zip: {inputs: ["$a", "$b"]}
... },
... as: "el",
... in: {
... $subtract: [
... {$arrayElemAt: ["$$el", 0]},
... {$arrayElemAt: ["$$el", 1]}
... ]
... }
... }
... }
... }
... }
... ]);
{ "_id" : ObjectId("5eefd7841994dbe8050da7b8"), "a" : [ 10, 20, 30, 40, 50 ], "b" : [ 1, 2, 3, 4, 5 ], "diff" : [ 9, 18, 27, 36, 45 ] }
Thanks for sending the full error message for your other problem. I’m still looking into why this is happening, but as you suggested it may be to do with having such a large number of fields. I’ll let you know when I have any further info on this.
Tom