Query over list in firebase

后端 未结 2 1640
走了就别回头了
走了就别回头了 2020-12-22 07:20

I\'ve the below custom model for firebase, I need to query for the cities with specific tags, I tried the below code but did not work :(

data class City(
            


        
2条回答
  •  我在风中等你
    2020-12-22 07:36

    My approach is to add some data to the searchable object on its onCreate trigger.

    // for structured data...
    // const myCity = { name: 'Baltimore', state: 'Maryland', country: 'USA' }
    // const names = [myCity.name, myCity.state, myCity.country]
    
    // or for strings, like names...
    const names = ["Benjamin Franklin", "Franklin Delano Roosevelt"]
    
    const searchArray = _.flatten(names.map(n => n.toLowerCase().split(' ')))
    const searchObject = searchArray.reduce((acc, n) => {
      acc[n] = true;
      return acc
    }, {})
    console.log(searchObject)
    // update the created object with searchObject

    On the client (in JS), to do a search...

    // say you're searching for "Franklin"
    let searchTerm = "Franklin"
    
    const key = `searchObject.${searchTerm.toLowerCase()}`
    const query = db.collection("MyCollection").where(key, '==', true)
    

提交回复
热议问题