【发布时间】:2021-03-06 02:24:04
【问题描述】:
我在实时数据库 firebase 中有一个包含两个表或集合 [coupons, categories] 的应用程序,我想获取属于特定类别 ID 的所有优惠券
我怎样才能获取这些数据?所以我的意思是在 firebase 中实现 one to many 关系
数据库
+ categories
- 1605426969
- count: 0
- createdDate: 1605426969
- id: 1605426969
- imageUri: "https://placeholder.png"
- 160542456
- count: 0
- createdDate: 1605426969
- id: 160542456
- imageUri: "https://placeholder.png"
+ coupons
- 1605515952
- category
- 1605426969
- count: 0
- createdDate: 1305426969
- id: 1605426969
- imageUri: "https://placeholder.png"
- code: "L1150"
- description: "my description"
- id: 1605515952
- imageUri: "https://avatar.png"
-url: "https://www.google.com/"
- 16055151325
- category
- 1605426969
- count: 0
- createdDate: 1305426969
- id: 1605426969
- imageUri: "https://placeholder.png"
- code: "L1150"
- description: "my description"
- id: 16055151325
- imageUri: "https://avatar.png"
- url: "https://www.google.com/"
所以我试着像下面这样获取它,但它不起作用,你能帮我吗。
//...
const app = Firebase.initializeApp(firebaseConfig)
const categoryRef = app.database().ref().child('categories')
const couponRef = app.database().ref().child('coupons')
const coupons = couponRef.orderByChild('category').equalTo('1605426969');
console.log(coupons);
【问题讨论】:
标签: javascript firebase vue.js firebase-realtime-database