在我的 raven3.5 实例中,我有一个集合,由于文档结构的变化,一些文档有一个额外的属性。现在我需要查询该属性,但许多旧文档没有它。
如何修补集合并将该属性添加到没有它的文档中?或者创建一个查询来获取不具有特定属性的文档?
谢谢。
最佳答案
以下是我所知道的适用于 RavenDB Server 4.2 及更高版本的内容:
选项 1 - 使用静态索引
创建一个 static index ('MyIndex') 与以下 map 方法:
from i in docs.Items
select new {
Name = i.Name
}
然后查询索引如下:
返回所有没有“名称”的“项目”:
from index 'MyIndex'
where true and not exists(Name)
选项 2 - 使用自动索引:
首先,运行以下查询,它将“创建” auto-index 为您:
from Items
where exists(Name)
之后,您可以查询以下内容以获取结果:
from Items
where true and not exists(Name)
============================================= ==
A patch 脚本由查询部分和更新部分
组成
因此,使用以下命令将缺少的属性添加到没有它的文档中:
from Items
where true and not exists(Name)
update {
this.Name = "value"
}
关于ravendb - 在属性不存在的 raven 3.5 中向文档添加一个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70003895/