查询的正确结构。没有得到日志输出
proper structure for query. not getting log output
我正在尝试在 firebase 中对我上传的一些测试数据执行一个简单的 equalTo()。这是代码。
var ref = new Firebase("https://crackling-fire-1105.firebaseio.com/business");
ref.orderByChild("city").equalTo("Pétion-Ville").on("child_added", function(snapshot) {
console.log(snapshot.key());
});
我在控制台中什么也没有得到。
如果我在自己的代码旁边使用 firebase 文档代码,它就可以工作。https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs");
ref.orderByChild("height").equalTo(25).on("child_added", function(snapshot) {
console.log(snapshot.key());
});
Index.on 错误我收到了。 (这已在下面的评论中解决)
FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "city" at /business to your security rules for better performance
第一次拿到后,加了.indexOn:"city"。我仍然收到该错误,并且在控制台中什么也没有。
这些是安全和规则控制台中的规则。
{
"rules": {
".read": true,
".write": true,
".indexOn": "city"
}
}
json结构如下:
{
business {
Joe's Designs: {
"accountid"
"address"
"city"
"email"
"heading"
"headingid"
"objectId"
"phonenumber1"
"website"
}
}
}
如有任何帮助,我们将不胜感激。谢谢。
在需要索引的键下方指定 .indexOn
。
{
"rules": {
"business": {
".indexOn": "\"city\""
}
}
}
这允许您为任何顶级密钥设置 .indexOn
规则。
从您的数据来看,您似乎在逃避密钥。我不确定你为什么要这样做,但这将要求你使用转义值进行索引和查询。
var ref = new Firebase("https://crackling-fire-1105.firebaseio.com/business");
ref.orderByChild("\"city\"").equalTo("Pétion-Ville").on("child_added", function(snapshot) {
console.log(snapshot.val());
});
我正在尝试在 firebase 中对我上传的一些测试数据执行一个简单的 equalTo()。这是代码。
var ref = new Firebase("https://crackling-fire-1105.firebaseio.com/business");
ref.orderByChild("city").equalTo("Pétion-Ville").on("child_added", function(snapshot) {
console.log(snapshot.key());
});
我在控制台中什么也没有得到。
如果我在自己的代码旁边使用 firebase 文档代码,它就可以工作。https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs");
ref.orderByChild("height").equalTo(25).on("child_added", function(snapshot) {
console.log(snapshot.key());
});
Index.on 错误我收到了。 (这已在下面的评论中解决)
FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "city" at /business to your security rules for better performance
第一次拿到后,加了.indexOn:"city"。我仍然收到该错误,并且在控制台中什么也没有。
这些是安全和规则控制台中的规则。
{
"rules": {
".read": true,
".write": true,
".indexOn": "city"
}
}
json结构如下:
{
business {
Joe's Designs: {
"accountid"
"address"
"city"
"email"
"heading"
"headingid"
"objectId"
"phonenumber1"
"website"
}
}
}
如有任何帮助,我们将不胜感激。谢谢。
在需要索引的键下方指定 .indexOn
。
{
"rules": {
"business": {
".indexOn": "\"city\""
}
}
}
这允许您为任何顶级密钥设置 .indexOn
规则。
从您的数据来看,您似乎在逃避密钥。我不确定你为什么要这样做,但这将要求你使用转义值进行索引和查询。
var ref = new Firebase("https://crackling-fire-1105.firebaseio.com/business");
ref.orderByChild("\"city\"").equalTo("Pétion-Ville").on("child_added", function(snapshot) {
console.log(snapshot.val());
});