简体   繁体   English

Firestore 多对多关系 - 如何更新数据?

[英]Firestore many to many relationships - How to update data?

Like a note app, you can set tags to a note.就像笔记应用程序一样,您可以为笔记设置标签。 Also, you can search notes with tag.此外,您可以使用标签搜索笔记。 Here is the firestore structure:这是firestore的结构:

notes(collection)
    note_1(doc)
        content: 'some words...'
        tags: ['apple', 'banana']

tags(collection)
    tag_1(doc)
        name: 'apple'
    tag_2(doc)
        name: 'banana'

If I change tag_1.name to 'new_apple', how shold I update note_1.tags?如果我将 tag_1.name 更改为“new_apple”,我应该如何更新 note_1.tags?

You're going to have to:你将不得不:

  1. Query for all notes documents where the tags array contains "apple"查询所有标签数组包含“apple”的notes文档
  2. Iterate the documents in the result set.迭代结果集中的文档。 For each document:对于每个文档:
    1. Update update the tags array in memory to remove "apple" and add "new_apple"更新更新 memory 中的标签数组以删除“apple”并添加“new_apple”
    2. Write the new tags array back to the document将新的标签数组写回文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从多对多关系中获取数据 - Fetching data from many-to-many relationships 有效更新 Firestore flutter 中的数据并防止多次写入 - Effeciently update data in firestore flutter and prevent many writes 如何在没有圈子的情况下建立多对多关系的模型 - How to model many to many relationships without circles 如何在 Laravel 中按多对多关系分组 - How to groupBy many to many relationships in Laravel 如何在django中过滤具有多对多关系的对象 - How to filter objects with many to many relationships in django MS Access:如何更新多个值和查询多个表(多对多关系)? - MS Access: How to update multiple values and query multiple tables (many to many relationships)? 我应该如何处理一对多关系来填充数据 model - How should I handle one to many relationships to fill a data model 如何将数据获取到 Eloquent 中具有许多关系的表 - How to get data to table that has many relationships in Eloquent sqlalchemy会话以*创建或更新具有许多关系的记录 - sqlalchemy session to create or update records with * to many relationships 如何在rdbms中建模许多“多对多”关系? - how to model many 'many-to-many' relationships in rdbms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM