Я пытаюсь запросить базу данных Cosmos, чтобы узнать идентификаторы всех ее контейнеров.
Используя приведенный ниже код, он дает мне ответ json, который является одним элементом (а не массивом).
Есть ли способ написать запрос, чтобы я получал только массив полей id из DocumentCollection. например, что-то вроде
[ { "id": "Summary-v00019"}, {"id": "Details-V00019"} ]
using Microsoft.Azure.Cosmos;
using System;
using System.IO;
namespace QueryDatabase
{
class Program
{
const string CosmosConnectionString = "AccountEndpoint=https://some-cosmos-ccount.documents.azure.com:443/;AccountKey=blahblah==;";
const string Database = "database-name";
static async System.Threading.Tasks.Task Main()
{
var cosmosClient = new CosmosClient(CosmosConnectionString);
var database = cosmosClient.GetDatabase(Database);
string queryText = "SELECT * FROM c";
QueryDefinition queryDefinition = new QueryDefinition(queryText);
FeedIterator feedIterator = database.GetContainerQueryStreamIterator(queryDefinition);
while (feedIterator.HasMoreResults)
{
using (ResponseMessage response = await feedIterator.ReadNextAsync())
{
using (var sr = new StreamReader(response.Content))
{
var text = sr.ReadToEnd();
Console.WriteLine(text);
}
}
}
}
}
}
JSON Ответ из приведенного выше кода:
{
"_rid": "blah==",
"DocumentCollections": [
{
"id": "Summary-v00019",
"indexingPolicy": {
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*"
}
],
"excludedPaths": [
{
"path": "/\"_etag\"/?"
}
]
},
"partitionKey": {
"paths": [
"/foo"
],
"kind": "Hash"
},
"conflictResolutionPolicy": {
"mode": "LastWriterWins",
"conflictResolutionPath": "/_ts",
"conflictResolutionProcedure": ""
},
"geospatialConfig": {
"type": "Geography"
},
"_rid": "blah=",
"_ts": 1591935021,
"_self": "dbs/blah==/colls/blah=/",
"_etag": "\"blah-blah-blah-0000-blah\"",
"_docs": "docs/",
"_sprocs": "sprocs/",
"_triggers": "triggers/",
"_udfs": "udfs/",
"_conflicts": "conflicts/"
},
{
"id": "Details-v00019",
"indexingPolicy": {
"indexingMode": "none",
"automatic": false,
"includedPaths": [],
"excludedPaths": []
},
"partitionKey": {
"paths": [
"/bar"
],
"kind": "Hash"
},
"conflictResolutionPolicy": {
"mode": "LastWriterWins",
"conflictResolutionPath": "/_ts",
"conflictResolutionProcedure": ""
},
"geospatialConfig": {
"type": "Geography"
},
"_rid": "blah=",
"_ts": 1591935021,
"_self": "dbs/blah==/colls/blah=/",
"_etag": "\"blah-0000-blah-0000-blah\"",
"_docs": "docs/",
"_sprocs": "sprocs/",
"_triggers": "triggers/",
"_udfs": "udfs/",
"_conflicts": "conflicts/"
}
],
"_count": 2
}