我有一些数据,我试图按照Firebase关于扁平结构的建议,所以我没有比我需要的更多。最终的结果是我在节点像这样有组织的报价:使用通配符作为路径的深层路径查询
quotes -> clientName -> quoteObject
的quoteObjects有一个'dateCreated会的价值,我希望能够拉像这样(这个数据时,我拉着一个大的所有的报价为特定页面的列表,然后我用对象分配,使对象的一个大阵列来显示):
const quotesRef = firebase.database().ref('quotes');
quotesRef.orderByChild('dateCreated').on('value', snapshot => {
// function
});
不幸的是,dateCreated会值超过一层深,标准查询不工作。我知道如果你知道父路径,你可以做一个深层路径查询,但在我的情况下,clientName父节点总是唯一的。鉴于此,是否可以指定一种通配符路径?如果是的话,我会怎么做呢?干杯!
编辑:显示数据库的例子,对不起应该是最初更具体。
quotes
- ClientEmailOne
-UniqueQuoteID
- createdBy: ClientEmailOne
- dateCreated: 1479255005172
- email: "[email protected]"
- ClientEmailTwo
-UniqueQuoteID
- createdBy: ClientEmailTwo
- dateCreated: 1479255005172
- email: "[email protected]"
- ClientEmailThree
-UniqueQuoteID
- createdBy: ClientEmailThree
- dateCreated: 1479255005172
- email: "[email protected]"
-UniqueQuoteID
- createdBy: ClientEmailThree
- dateCreated: 1479255005172
- email: "[email protected]"
-UniqueQuoteID
- createdBy: ClientEmailThree
- dateCreated: 1479255005172
- email: "[email protected]"
感谢您的快速响应弗拉NK!所以只是为了澄清对不起,这是否意味着它应该已经按照现在的价值排序(即使它嵌套了几个深度)?或者它是不可能的?因为它回来未分类。谢谢 –
Firebase可以通过嵌套的孩子*仅限于*当这些孩子在固定路径上。所以你可以订购'ref.child(“quotes”)。orderByChild(“property/under/clientName”)',但不是'ref.child(“quotes”)。orderByChild(“property/???/clientName”) ' –
好的感谢澄清。因此,鉴于Firebase建议以这种方式构建数据,例如在具有各种ID密钥的单独节点下,他们又如何推荐以这种方式进行查询?这似乎是相当普遍,简单的事情,预计必须做的?还是假设您只是按照原样提取数据并对其进行排序呢? –