collection.findOneDocument(filter: queryFilter) { result in
switch result {
case .failure(let error):
print("Did not find a document")
return
case .success(let document):
print("Found a matching document: \((document?.first?.value)!)")
}
}
But my document has 2 arrays of nested documents that are returned as just arrays of id’s. How do I populate the nested documents in the query?
I appears you’re using the Swift SDK, not the RealmSwift SDK - you may want to take a look a the RealmSwift SDK as it adds a few more features and makes queries a bit simpler and getting back deep associated data more clean (just IMO)
We will need a bit more info though - the question states the arrays contains nested documents but then says it’s an array of id’s, and it can’t be both, well, it can be.
If it’s an array of ID’s (as just text for example) you may need to craft a separate query to retrieve those.
If it’s an array of documents then well, there they are!
On the other hand, you may just need to unwind the array to get the documents. See Unwind Array Values and see if that applies.
I think the question needs more data - can you edit it to include the structure of your document. Including your Realm Models would help as well.
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"]))")
}
}
}