如何在Firebase中的数组对象的子属性上创建索引 [英] How to create an index on a child property of an array object in Firebase
问题描述
在我的firebase应用程序中,我使用生成唯一ID的push()方法将对象存储在数组结构中。这些对象有一个名为scheduledDate的子属性如何在firebase中创建一个indexOn规则来索引此字段。在事件下,每个用户都有一个节点,而不是他们事件的子数组。 / events / userId / arrayOfEvents
我可以使用orderByChild()成功检索事件的计划日期的记录,但它警告我索引。 b
$ b
我的规则如下所示:
events:{
.read:auth!= null,
.write:auth!= null,
.indexOn:[scheduledDate]
}
执行查询的代码如下所示:
this.dbEvents = new Firebase(firebaseEventsUrl);
var q;
q = this.dbEvents.child(userId).orderByChild(scheduledDate)。limitToLast(limitToLast);
return $ firebaseArray(q);
我的数据如下所示:
事件:{
user1:{
-K2NYCT2_uMwsTSfH58O(推送生成):{
描述:'event 1',
scheduledDate:1446730200000
},
--K2NyNh660I4k8loar-z:{
描述:'event 2',
scheduledDate:1446730200000
},
},
user2:{
}
}
{
rules:{
events :{
.read:auth!= null,
.write:auth!= null,
$ uid:{
.indexOn:scheduledDate
}
}
}
}
In my firebase app I am storing objects in an array structure using the push() method that generates unique ids. These objects have a child property called "scheduledDate" How can I create an indexOn rule in firebase to index this field. under events each user has a node, than a child array of their events. /events/userId/arrayOfEvents
I can use orderByChild() to successfully retrieve the records by event scheduled date, but its warning me about the index.
My rules looks like this:
"events":{
".read" : "auth != null",
".write" : "auth != null",
".indexOn": ["scheduledDate"]
}
My code doing the query looks like this:
this.dbEvents = new Firebase(firebaseEventsUrl);
var q;
q = this.dbEvents.child(userId).orderByChild("scheduledDate").limitToLast(limitToLast);
return $firebaseArray(q);
My data looks like this:
events:{
user1:{
-K2NYCT2_uMwsTSfH58O(push generated):{
description: 'event 1',
scheduledDate: 1446730200000
},
--K2NyNh660I4k8loar-z:{
description: 'event 2',
scheduledDate: 1446730200000
},
},
user2:{
}
}
This should work:
{
"rules": {
"events":{
".read" : "auth != null",
".write" : "auth != null",
"$uid": {
".indexOn": "scheduledDate"
}
}
}
}
这篇关于如何在Firebase中的数组对象的子属性上创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!