Reputation: 25312
I'm trying to fetch documents by specific type. Here's my first attempt based on documentation:
var dataStoreStatuses =
_documentClient.CreateDocumentQuery<DataStoreStatus>(
DocumentService.CollectionUri, new FeedOptions() {
EnableCrossPartitionQuery = true })
.ToList();
The problem is this request returns even documents that don't comply to DataStoreStatus schema. I guess that's how it's supposed to work as Cosmos Db is schemaless (though documentation says that DataStoreStatus defines the type of object to query
).
I used to use RavenDb and it stored the type of document, so this kind of queries were really easy to execute. Is there a way to achieve that in Cosmos Db?
Upvotes: 0
Views: 1491
Reputation: 5004
As you already mentioned, DocumentDB is schemaless. When the documentation says that "DataStoreStatus defines the type of object to query" then I believe what you are looking at is the documentation of client API. The specific generic type argument is not actually part of query sent to DocumentDB storage, but used as a second step after fetching the documents to help automatically map the returned documents to the types you want. The latter step is purely client side.
So, to my knowledge, it is by design that you cannot query documents by type with your query.
Workaround
If you need to query documents by type then you need to store such information to the documents themselves. It's quite common to have a property named "type" or such. Then you could do a query:
select * from c where c.type = 'DataStoreStatus'
Note that your entity type should then also contain that field.
Upvotes: 2