So here is what I want the documents in my collection to look like structurally:
{
"_id": "123",
"systems": [
{
"_id": "1338",
"metrics": [
"TEST"
]
}
]
}
My goal is to be able to do a single update/insert (using upsert=True) for any instance that the system and/or metric does/doesn't exist in their respective arrays. Currently my only work around is making to update calls as follows:
if not collection.find_one({"_id": "123", "systems._id": "1338"}):
collection.update(
{"_id": "123"},
{"$addToSet": {"systems": {"_id": "1338"}}},
upsert=True)
collection.update(
{"_id": "123", "systems._id": "1338"},
{"$addToSet": {"systems.$.metrics": "TEST"}},
upsert=True)
Thanks