Firebase Query Double Nested

后端 未结 3 1314
清歌不尽
清歌不尽 2020-11-21 04:45

Given the data structure below in firebase, i want to run a query to retrieve the blog \'efg\'. I don\'t know the user id at this point.

{Users :
     \"123         


        
3条回答
  •  时光取名叫无心
    2020-11-21 05:16

    Given your current data structure you can retrieve the User that contains the blog post you are looking for.

    const db = firebase.database()
    const usersRef = db.ref('users')
    const query = usersRef.orderByChild('blogs/efg').limitToLast(1)
    query.once('value').then((ss) => {
      console.log(ss.val()) //=> { '7654321': { blogs: {...}}}
    })
    

    You need to use limitToLast since Objects are sorted last when using orderByChild docs.

提交回复
热议问题