I would like to determine if at least one document exist that matches the where clause. I don't need the count. And I don't need the documents. And I prefer cosmosDb to stop looking once anything is found. So it should be faster / cheaper than count(). Maybe something like this but better. Linq solutions would be fine too.
SELECT
value true
FROM
aContainer c
WHERE
c.aField = @aValue and
c.anotherField = @anotherValue
OFFSET 0 LIMIT 1
or
var exists = await _aContainer.GetItemLinqQueryable<EnrollmentDate>(true)
.Any(r=>r.aField == value && r.anotherField == @anotherValue);
You can use the following linq statement.
var feed = container
.GetItemLinqQueryable<EnrollmentDate>()
.Where(x => !x.Id.IsNull()) // your own filter
.Select(x => 1)
.Take(1)
.ToFeedIterator();
var anyResult = false;
while (feed.HasMoreResults)
{
foreach (var item in await feed.ReadNextAsync())
{
anyResult = true;
}
}
Which will generate the following query:
SELECT TOP 1 VALUE 1 FROM root WHERE ...