Getting documents from a collection by their respective IDs can be done via the get()
function on a client.collection(name)
object:
docs = ctx.client.collection("books").get(["lotr", "moby"])
The result is a key-value mapping: each key is a document ID, and each value is the document in the same shape it was upserted:
# Example response
{
"lotr": {
"_id": "lotr",
"title": "The Lord of the Rings",
"author": "J.R.R. Tolkien",
"published_year": 1954
},
"moby": {
"_id": "moby",
"title": "Moby Dick",
"author": "Herman Melville",
"published_year": 1851
}
}
If a document with a given ID does not exist in the collection, it is simply omitted from the results; no error is thrown.