使用FireBase实时数据库时,不能使用
orderBy()
在一个字段上,然后使用
equalTo()
在另一个领域。你不能用两种不同的
命令字节()
.
这在文件中有详细说明。
here
(角火焰2)
)
here
(“标准”JavaScript SDK)。
但是,可以使用组合值,例如
active_lastname
使用如下查询:
var database = firebase.database();
database
.ref('users')
.orderByChild('composedValue')
.startAt('true_')
.endAt('true_\uf8ff')
.once('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
console.log(childKey);
console.log(childData);
});
});
您编写的值如下:
true_Obama
true_Bush
false_Carter
....
因此,对于angularfire2,根据您的代码,它将是:
getAllUsers() {
return this.fireBase.list(
'/users',
ref => ref
.orderByChild('composedValue')
.startAt('true')
.endAt('true\uf8ff')
).valueChanges();
}