0

我正在使用 firestore where() 方法来测试嵌套字段与另一个值的相等性。嵌套字段位于文档结构中:Apartments/Apartment/property/address/ locality_short

这是我目前的做法(在下面的代码中),但它没有返回任何文档: //There import import { AngularFirestore} from 'angularfire2/firestore';

//注入构造函数(private afs: AngularFirestore){}

//根据是否 //apartment.property.address.locality_short == search_object.locality_short 来检索公寓的方法

search(search_obj: Search):Observable{ return this.afs.collection('/Apartments', ref => ref.where( property,address,locality_short, '==', 'search_obj.Address.locality_short')).valueChanges() }

4

1 回答 1

0

Solved! after trying out different ways of expressing the nested fieldPath, it turns out that using the dot '.' to separate the nesting levels works just fine and my other mistake was expressing the value in my where() method as a string instead of as an actual value. So the code below works and returns results based on the evaluation of a nested fieldPath against a value in the where() method of angularfirestore

search(search_obj: Search):Observable{ return this.afs.collection('/Apartments', ref => ref .where(property.address.locality_short,'==',search_obj.Address.locality_short)) .valueChanges() }

于 2018-04-29T11:25:08.243 回答