在Firestore中创建空文档 [英] Creating Empty Documents in Firestore

查看:43
本文介绍了在Firestore中创建空文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Firestore中的系统会自动删除集合中的空文档.但是,我现在遇到这样一种情况,即文件名起了作用.我有一个名为用户名的集合,并且在其中有许多ID为用户名的文档.例如,我可能会在数据库中看到usernames/bob_marley.这里的问题是,由于文档中没有任何字段,因此它们会被自动删除,从而破坏了设置的目的.在这种情况下,我应该如何构建数据库?

I understand that empty documents within collections are removed automatically by the system in Firestore. However, I have a situation now where the name of the document serves a purpose. I have a collection named usernames, and within this, many documents with the ID being the username. For instance, usernames/bob_marley is what I might see in the database. The problem here is that, since the documents do not have any fields in them, they get removed automatically thereby defeating the purpose of the set-up. How should I be structuring my database in these cases?

谢谢

推荐答案

最简单的事情就是根本不允许文档为空.使用(例如)"exists = true"在其中保留一个属性,并确保它永远不会被删除.如果您担心用户不小心自己对自己执行此操作,请使用安全规则来防止这种情况.

The easiest thing to do is simply not allow the document to ever become empty. Keep one property in it with (for example) "exists = true" and make sure it never gets removed. Use a security rule to prevent this, if you're concerned about users accidentally doing this to themselves.

另一件事是重新评估您要对系统中的空文档执行的操作,是否值得考虑如何以最能满足您要查询的方式构造数据表演.

Another thing to do is re-evaluate what exactly you're trying to do with an empty document in the system, and if it's worthwhile to think about how to structure your data in a way that best meets the queries you want to perform.

这篇关于在Firestore中创建空文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆