Thanks so much for the reply, @Jay . Here’s some more info.
The models.
Recipe:
_id: String? = ObjectId.generate().stringValue
author: String = ""
title: String? = nil
directions = RealmSwift.List<Direction>()
ingredients = RealmSwift.List<Ingredient>()
Ingredient:
_id: String? = ObjectId.generate().stringValue
author: String = ""
name: String? = nil
Direction:
_id: String? = ObjectId.generate().stringValue
author: String = ""
text: String? = nil
For most purposes, I synch with author as the partition. But in this edge case, I want to access a Recipe document that is outside of the current user’s partition. I’ve tried a few different angles. But this has been the most promising. Here, I’m just logging the nested ingredients documents as I try to figure out how to unpack them.
let client = app.currentUser!.mongoClient("mongodb-atlas")
let database = client.database(named: "funky_radish_db")
let collection = database.collection(withName: "Recipe")
let queryFilter: Document = ["_id": "617bf8c26bd5c64cafe9233e"]
collection.findOneDocument(filter: queryFilter) { result in
switch result {
case .failure(let error):
print("Did not find matching document")
return
case .success(let document):
print("Found a document: \((document?["ingredients"]))")
}
}
}
But this is what I’m getting back:
**Optional(Optional(RealmSwift.AnyBSON.array([Optional(RealmSwift.AnyBSON.string("617d78976200a9a598c9ca44")), Optional(RealmSwift.AnyBSON.string("617d78976200a9a598c9ca45")), Optional(RealmSwift.AnyBSON.string("617d78976200a9a598c9ca46")), Optional(RealmSwift.AnyBSON.string("617d78976200a9a598c9ca47")), Optional(RealmSwift.AnyBSON.string("617d78976200a9a598c9ca48"))])))**
So I’m trying to make that next jump from this optional array of optional RealmSwift.AnyBSON.string, to the documents with the included data.