【发布时间】:2021-07-19 11:22:37
【问题描述】:
我正在从我的 cosmos db sql api 集合中读取所有文档,并且我想过滤掉那些在 json 中定义了特定属性的文档。因此,如果文档属于此架构
{
id: 1
name: aaa
project: ssdf
}
我想过滤掉其中包含“项目”属性的文档。到目前为止,我的代码可以从集合中读取文档:
do
{
var feed = await client.ReadDocumentFeedAsync(
UriFactory.CreateDocumentCollectionUri( SourceDatabase, SourceCollection ),
new FeedOptions { MaxItemCount = 10, RequestContinuation = continuationToken } );
continuationToken = feed.ResponseContinuation;
foreach( Document document in feed )
{
Console.WriteLine( document );
}
}
我在 Cosmos db 中获取过滤文档的查询是 select * FROM c WHERE IS_DEFINED(c.Project)。如何在上面的代码中做到这一点?
在 Gaurav 回答后更新问题:
static async Task Main()
{
string continuationToken = null;
DocumentClient client = new DocumentClient( new Uri( endpointUrl ), authorizationKey );
var feed = client.CreateDocumentQuery(
UriFactory.CreateDocumentCollectionUri( SourceDatabase, SourceCollection ).ToString(),
new SqlQuerySpec( "select * FROM c WHERE IS_DEFINED(c.Project)" ),
new FeedOptions { MaxItemCount = 100, EnableCrossPartitionQuery=true } ) ;
continuationToken = feed.
foreach( Document document in feed )
{
Console.WriteLine( document.Id );
}
【问题讨论】:
标签: c# azure-cosmosdb