AngularFire2 按子对象查询
AngularFire2 query by child object
Angular 应用程序使用 AngularFire2。我试图在子对象上查询 firebase,而不仅仅是子字符串 属性。按子字符串查询 属性 有效,但我如何按整个对象查询。
此代码有效
// Given the following firebase data structure
httpCache: {
{ID}: {
url: 'www.fakeurl',
otherProperties: {}
}
}
// This code will return results if exists where the url matches
this.af.database.list('httpCache', {
query: {
orderByChild: 'url',
equalTo: 'www.fakeurl'
}
}).subscribe(x => {
if (x.length > 0) { console.log('match found!'); }
});
此代码无效:
// Given the following firebase data structure
httpCache: {
{ID}: {
request: {
url: 'www.fakeurl',
params: 'id=1'
},
otherProperties: {}
}
}
// This code throws an exception
let request = {
url: 'www.fakeurl',
params: 'id=1'
};
this.af.database.list('httpCache', {
query: {
orderByChild: 'request',
equalTo: request
}
}).subscribe(x => {
if (x.length > 0) { console.log('match found!'); }
});
例外情况:
Query: First argument passed to startAt(), endAt(), or equalTo() cannot be an object.
我正在尝试使用此处显示的第二种解决方案,其中过滤条件被推送到包含所有过滤属性的子对象中:
Query based on multiple where clauses in firebase
您不能查询对象。所以这是无效的并导致错误:
let request = {
url: 'www.fakeurl',
params: 'id=1'
};
this.af.database.list('httpCache', {
query: {
orderByChild: 'request',
equalTo: request
}
})
正如我在 the question you linked 中回答的那样,您可以添加一个 属性,其中包含您要查询的组合值。但是随后您还需要在实际查询调用中组合这些值,而您并没有这样做。
不可能说出您是如何组合这些值的,但假设您只是将 URL 和参数连接起来,您将查询为:
let request = 'www.fakeurl_id=1'
this.af.database.list('httpCache', {
query: {
orderByChild: 'request',
equalTo: request
}
})
Angular 应用程序使用 AngularFire2。我试图在子对象上查询 firebase,而不仅仅是子字符串 属性。按子字符串查询 属性 有效,但我如何按整个对象查询。
此代码有效
// Given the following firebase data structure
httpCache: {
{ID}: {
url: 'www.fakeurl',
otherProperties: {}
}
}
// This code will return results if exists where the url matches
this.af.database.list('httpCache', {
query: {
orderByChild: 'url',
equalTo: 'www.fakeurl'
}
}).subscribe(x => {
if (x.length > 0) { console.log('match found!'); }
});
此代码无效:
// Given the following firebase data structure
httpCache: {
{ID}: {
request: {
url: 'www.fakeurl',
params: 'id=1'
},
otherProperties: {}
}
}
// This code throws an exception
let request = {
url: 'www.fakeurl',
params: 'id=1'
};
this.af.database.list('httpCache', {
query: {
orderByChild: 'request',
equalTo: request
}
}).subscribe(x => {
if (x.length > 0) { console.log('match found!'); }
});
例外情况:
Query: First argument passed to startAt(), endAt(), or equalTo() cannot be an object.
我正在尝试使用此处显示的第二种解决方案,其中过滤条件被推送到包含所有过滤属性的子对象中: Query based on multiple where clauses in firebase
您不能查询对象。所以这是无效的并导致错误:
let request = {
url: 'www.fakeurl',
params: 'id=1'
};
this.af.database.list('httpCache', {
query: {
orderByChild: 'request',
equalTo: request
}
})
正如我在 the question you linked 中回答的那样,您可以添加一个 属性,其中包含您要查询的组合值。但是随后您还需要在实际查询调用中组合这些值,而您并没有这样做。
不可能说出您是如何组合这些值的,但假设您只是将 URL 和参数连接起来,您将查询为:
let request = 'www.fakeurl_id=1'
this.af.database.list('httpCache', {
query: {
orderByChild: 'request',
equalTo: request
}
})