tHatpart
tHatpart

Reputation: 1136

Query Firebase value inside AutoID in Swift

I want to check if a certain userid is in the usedBy child to ensure a user cannot use it twice, but I am having trouble trying to query the usedBy child since it is entered by AutoID

I have something like this in Swift, but does not accomplish what I need, but do now know how to query it correctly:

promoCodes.child(code).child("usedBy").queryEqual(toValue: userid).observeSingleEvent(of: .value) { snapshot in }

enter image description here

Upvotes: 0

Views: 21

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598951

Firebase Realtime Database queries always consist of two parts:

  1. First you order the data on either the key, the (single, atomic) value, or on the value of a property.
  2. Then you filter the data based on those value.

You're missing the first part in your query, which would be:

promoCodes.child(code).child("usedBy").queryOrdered(byChild:"userid").queryEqual(toValue: userid).

Upvotes: 1

Related Questions