1

Is it posible make this query in Firebase? I need put OR conditionals where '//OR' is written blow. Does anyone know how to do it?

firebase.database().ref().child('reservation')
.orderBy('date').equalTo(date)
//AND
  (  
     .orderBy('enterHourSelected').endAt(enterHourSelected)
     .orderBy('outHourSelected').startAt(enterHourSelected)
   //OR
     .orderBy('enterHourSelected').startAt(enterHourSelected)
     .orderBy('outHourSelected').endAt(outHourSelected)
   //OR
     .orderBy('enterHourSelected').endtAt(outHourSelected)
     .orderBy('outHourSelected').startAt(outHourSelected)
  )
  .once('value', snapshot => {
             ...
});
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Diego Barranco
  • 89
  • 1
  • 2
  • 9

1 Answers1

1

No this is not possible, you can only query on one child,key or value

So you are able to do this:

const ref=rootRef.child('reservation').orderBy('date').equalTo(date);

const ref=rootRef.child('reservation').orderBy('date').startAt("enterHourSelected").endAt(enterHourSelected);

const ref=rootRef.child('reservation').orderBy('date').limitToFirst(10);

const ref=rootRef.child('reservation').orderBy('date').limitToLast(10);

You will get an error if you execute the above code in the question

then when you want to retrieve data you can only use one of the above:

rootRef.child('reservation').orderBy('date').equalTo(date).once('value', snapshot => {
 //retrieve here

 });
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134