Electron 在NeDB中,一个文档中的数组是否比多个文档更好?
我正在使用NeDB作为数据库制作一个电子应用程序。Electron 在NeDB中,一个文档中的数组是否比多个文档更好?,electron,nedb,nosql,Electron,Nedb,Nosql,我正在使用NeDB作为数据库制作一个电子应用程序。 文件结构如下: For a machine (<= 150 machines), I need to add a comment for the machine regularly. 对于每个条目,制作一份包含机器编号的新文档 { machine_no : string, date: Date, comment: string } 我需要插入、查看和更新现有数据的操作。 对于这种情况,哪种文档结构更好?为什么
文件结构如下:
For a machine (<= 150 machines), I need to add a comment for the
machine regularly.
{
machine_no : string,
date: Date,
comment: string
}
对于这种情况,哪种文档结构更好?为什么?这取决于您的使用情况。与NeDB所基于的MongoDB非常相似,数组适用于“父”和“子”相互关联的情况。例如,在对每个项使用
$push
的同时增加注释计数,这对于数组来说更好,而不是写入将被放入两个不同名称空间的内容。另一方面,如果您需要执行“更新所有日期值”之类的操作,那么通常最好有单独的条目。也要清楚。在这种情况下,对于“数组”,实际上应该只有“一个”。正如在{machine:1,data:[{date:1,comment'a'},{date:2,comment'b'}]}
中一样。否则,保持相互关联的指数就太难了。
{
machine_no : string,
date: Date,
comment: string
}