使用 array_contains 过滤条件查询 Firestore 集合

使用 array_contains 过滤条件查询 Firestore 集合

包含此代码示例的文档页面

如需查看上下文中使用的代码示例,请参阅以下文档:

代码示例

Go

query := cities.Where("regions", "array-contains", "west_coast").Documents(ctx)

Java

CollectionReference citiesRef = db.collection("cities");
Query westCoastQuery = citiesRef.whereArrayContains("regions", "west_coast");

Node.js

const westCoastCities = citiesRef.where('regions', 'array-contains',
  'west_coast').get();

PHP

$containsQuery = $citiesRef->where('regions', 'array-contains', 'west_coast');

Python

cities_ref = db.collection(u'cities')

query = cities_ref.where(u'regions', u'array_contains', u'west_coast')

Ruby

cities_ref = firestore.col collection_path
cities = cities_ref.where "regions", "array-contains", "west_coast"

后续步骤

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