首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >firebase数据库存储项目列表

firebase数据库存储项目列表
EN

Stack Overflow用户
提问于 2016-07-15 20:27:51
回答 1查看 4.2K关注 0票数 0

这里是我的代码

代码语言:javascript
复制
    //1. Add menu items to the globalMenu and to restaurant, and the restaurantId of the restaurant adding menu.
    this.writeNewMenuItem = function(itemName, restaurantId) {
        // A post entry.
        var menuItem = {
            itemName: [itemName]
        };

        var ref = firebase.database().ref();

        // Get a key for a new Post.
        var newItem = ref
          .child('globalMenu')
          .push(menuItem);

        ref
          .child('restaurants')
          .child(restaurantId)
          //.child(newItem.key)
          .update(menuItem);

    }

  1. 还让我知道推送和弹出这些项目的方法。
  2. 和if duplicate found这不应该插入。
  3. 我想获取匹配的字符项目,比如如果我在查询中传递'app‘,这应该返回'apple,application,appengine’等。我该怎么做?
EN

回答 1

Stack Overflow用户

发布于 2017-08-15 16:19:27

您应该尽量避免在Firebase数据库中使用“数组”,因为:

...对于分布式数据,它们是不可靠的,因为它们缺乏唯一的、永久的方式来访问每条记录。

https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html

关于您的第三个问题:以这种方式查询数据库是不可能的,您需要接收所有子节点的完整列表,并在客户端进行过滤。我建议阅读结构化数据的最佳实践:https://firebase.google.com/docs/database/admin/structure-data

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38396123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档