0

Please Help!!!!

Im using firebase admin, In my case I'm searching for a value in multiple fields, can't figure out how to draft a query for the same.

Expected:

db.collection("user")
.where("name, comments", "in", "Jack" )
.get()

(or)

db.collection("user")
.where("name, comments", "==", "Jack" )
.get()

But, unfortunately i couldnt find a solution for executing this scenario.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Preethi
  • 1
  • 2
  • Please post screenshot of your Firestore Document structure and explain – Dharmaraj Apr 17 '21 at 15:46
  • What you are doing is called a "logcal OR" query, which is not supported by Firestore. You will have to perform two queries, one for name and one for comments, and check the results of both queries. Firestore only supports "logical AND" queries that filter across multiple fields - all of the filter conditions must evaluate true for a document in order to find a match. – Doug Stevenson Apr 17 '21 at 15:48
  • Consider also restructuring your data to add a single field that contains the intersection of values. If you had a field called name_or_comments where the value was only set if it has same between the two fields name and comments, you could filter on that instead to find matches. – Doug Stevenson Apr 17 '21 at 15:51
  • @DougStevenson i tried two separate queries and combined its result like you suggested. thanks a lot. – Preethi Apr 17 '21 at 16:48

0 Answers0