Flutter Firestore where clause using map

后端 未结 1 515
面向向阳花
面向向阳花 2021-01-13 08:35

When a new activity is posted i add a new post document into the collection. Inside this document i have a map where users add confirmation to the event marking it as true a

相关标签:
1条回答
  • 2021-01-13 09:28

    You'll want to turn the confirmations field into an array, and use the (relatively recent) array-contains and arrayUnion operations.

    The equivalent query with an array like that would become:

    var snap = await Firestore.instance
        .collection('user_posts')        
        .where("confirmations", arrayContains: user.id)
        .getDocuments();
    

    And this way you only need an index on confirmations, which is added automatically.

    For more on these see:

    • the blog post introducing these operations
    • the documentation on updating arrays
    • the documentation on array membership queries
    0 讨论(0)
提交回复
热议问题