null字段或bool = mongoDB中的true

发布于 2025-02-13 03:45:50 字数 483 浏览 1 评论 0原文

假设我希望游戏中的某些物品可穿戴,而另一些则不是。我可以使用{“可耐磨性”:true}带有{“可耐磨性”:false},或{“可耐磨性”:null}使用{}。乍一看,第二个解决方案看起来更笨拙,但表现可能会有些笨拙,但性能并不是这里最重要的事情。

想象一下,我们需要10个这样的布尔值:可穿戴,可放置,装备等。那么,它不仅是更多的磁盘空间,而且每个游戏项目的文档也变得肿,使用并不是很好。相反,我们只能在需要它们的地方才有这些字段。但是,然后{“可穿戴”:null}看起来不会很直观。如果有人可以编写{“可穿戴”},这将是完美的,这意味着与{“可戴”:null}相同,但不幸的是没有这样的东西。也许,我缺少一些重要的东西,这将是一个更好的解决方案。

因此,我应该在这里使用布尔字段,空字段还是有其他更好的解决方案?

Let's say I want some items in my games to be wearable, and others not. I could do it using either {"wearable": true} with {"wearable": false}, or {"wearable": null} with {}. The second solution looks clunkier at first glance but is probably a little more performative, yet performance is not the most important thing here.

Imagine we need 10 such booleans for each item: wearable, placeable, equipable, etc. Then it's not just more disk space, but also each document for a game item becomes bloated and not very nice to use. Instead, we could have these fields only where we need them. But then {"wearable": null} doesn't look very intuitive. It would be perfect if one could write {"wearable"} and it would mean the same as {"wearable": null}, but unfortunately there's no such thing. Perhaps, I'm missing something important that would be a better solution here.

So should I use boolean fields, null fields, or there's a different better solution here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文