Firebase实时数据库,“使用OR值查询的位置”

时间:2020-09-01 04:08:13

标签: firebase firebase-realtime-database

如何在要提供一系列匹配值的实时数据库中执行查询?

示例数据结构

{
  movies: {
    "<firebase-push-id>": {
      id: 1,
      title: 'Neverending Story'
    },
    "<firebase-push-id>": {
      id: 2,
      title: 'The Little Mermaid'
    },
    "<firebase-push-id>": {
      id: 3,
      title: 'The Lion King'
    },
    "<firebase-push-id>": {
      id: 4,
      title: 'Hannibal'
    }
  },
  users: {
    "<firebase-push-id>": {
      id: 1,
      title: 'Jim',
      favouriteMoviesId: {
        "<firebase-push-id>": 1,
        "<firebase-push-id>": 2
        "<firebase-push-id>": 3
      }
    },
    "<firebase-push-id>": {
      id: 1,
      title: 'Jo',
      favouriteMoviesId: {
        "<firebase-push-id>": 4
      }
    },
    "<firebase-push-id>": {
      id: 1,
      title: 'Bob',
      favouriteMoviesId: {}
    }
  }
}

如果我已经有了“ Jim”的引用,如何使用favouriteMoviesId运行查询以获取他最喜欢的电影对象?

编辑:根据要求,我已经有了一些代码-本质上是如何获得“吉姆”参考的:

firebase.database().ref(`users/${userId}`).on('value', (snapshot) => {
  const user = snapshot.val();
  // now I have user.favouriteMoviesId available
})

0 个答案:

没有答案