I manage to get all the document by query the userId
:
this.orderListRef = firebase.database().ref(`/orderList`);
this.orderListRef.orderByChild('userId').equalTo(`${this.currentUser.uid}`)
But i having problem to get all the document by query the sub key restId
in the order
array, i did try below codes but it just return null
:
this.orderListRef.orderByChild('order/restId').equalTo('-L6vQHDBv9WugS_yTibn').on('value', snap => {
console.log(snap.val())
})
and
this.orderListRef.child('order').orderByChild('restId').equalTo('-L6vQHDBv9WugS_yTibn').on('value', snap => {
console.log(snap.val())
})
Please help.. I would like to get return that contain "-L6vQHDBv9WugS_yTibn"
in the restId
key only, like:
-L9IZKHkueFppGMJY3Z9: {deliveryAddress: "Kuala Lumpur, Federal Territory of Kuala Lumpur, Malaysia", dtcreate: 1522894198149, order: Array(2), userId: "AeMgnwHy3Hav3FE9DyTMJVdp4QX2", userOrderNumber: "pGMJY3Z9"}
-L9I_DcXgx_fjsmsn2rm: {deliveryAddress: "Kuala Lumpur, Federal Territory of Kuala Lumpur, Malaysia", dtcreate: 1522894433661, order: Array(2), userId: "AeMgnwHy3Hav3FE9DyTMJVdp4QX2", userOrderNumber: "jsmsn2rm"}
-L9IksHXG4WZo0ejfmk1: {deliveryAddress: "Kuala Lumpur, Federal Territory of Kuala Lumpur, Malaysia", dtcreate: 1522897487221, order: Array(2), userId: "AeMgnwHy3Hav3FE9DyTMJVdp4QX2", userOrderNumber: "o0ejfmk1"}
Thank you in advance!
Edited 1:
After Frank van Puffelen suggest the method of creating restaurant
as a child of the orderList > ID, i found that it is good idea and i tried, but still no luck.
Heres the new screenshot of my DB:
I have tried with below queries but everyone still returning null
:
this.orderListRef.orderByChild('restaurant').equalTo('rest001').once('value', snap => {
console.log(snap.val())
})
this.orderListRef.child('restaurant/rest001').once('value', snap => {
console.log(snap.val())
})
this.orderListRef.child('restaurant').equalTo('rest001').once('value', snap => {
console.log(snap.val())
})
this.orderListRef.child('restaurant').orderByChild('rest001').once('value', snap => {
console.log(snap.val())
})
Thank you for responding!