0

How do I query a value inside an object in an array using firebase firestore?

  • NodeJs
  • Firebase Admin SDK

as an example :

  firestore collection (Users)
----------------------------
  in document (user1) 
    ids = [
    {
      id : "fdsgdfg",
      date : "2021-1-1"
    },
    {
      id : "wewer",
      date : "2022-12-1"
    }
  ]
----------------------------
  in document (user2) 
    ids = [
    {
      id : "fer392jfw",
      date : "2021-2-5"
    }
  ]
  */
  // gives me
  const isID1 = await db.collection("Tokens").where("ids", "array-contains", {id : "fdsgdfg",date : "2021-1-1"}).get();

  // not give me
  const isID2 = await db.collection("Tokens").where("ids", "array-contains",{id : "fdsgdfg"}).get();

  // i need This   (without adding date)
  • It's not possible to do what you're asking. array-contains queries always use the entire item stored in the array. You will have to move or copy the nested maps fields from the array of maps into a single top-level array field to query it with array-contains. – Doug Stevenson Jan 23 '23 at 00:53

0 Answers0