对多个字段使用范围和不等式过滤条件的复合查询

请提供 C# 和 Ruby 示例,这些示例与最初在 Firestore 文档计划中针对多个不等式(GA 和 bug 351980346)请求的 Firestore 和 Datastore 示例相匹配。 请求针对 Turbo/469184。

代码示例

C#

如需向 Firestore 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

CollectionReference citiesRef = db.Collection("cities");
Query query = citiesRef
    .WhereGreaterThan("Population", 1000000)
    .WhereLessThan("Density", 10000);
QuerySnapshot querySnapshot = await query.GetSnapshotAsync();
foreach (DocumentSnapshot documentSnapshot in querySnapshot)
{
    var name = documentSnapshot.GetValue<string>("Name");
    var population = documentSnapshot.GetValue<int>("Population");
    var density = documentSnapshot.GetValue<int>("Density");
    Console.WriteLine($"City '{name}' returned by query. Population={population}; Density={density}");
}

PHP

如需向 Firestore 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

$chainedQuery = $collection
    ->where('age', '>', 35)
    ->where('height', '>', 60)
    ->where('height', '<', 70);

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器