RavenDb 使用 RQL 添加 属性

RavenDb add property using RQL

有没有办法使用 RQL(Patch) 将 属性 添加到集合中的所有文档?

Bulk-Insert is a possible solution, but it's required to write c# code, which is not a fast solution to achieve, specially in a matter that you need to manipulate your data and need to go back and forth for many times.

您可以使用 Patching 添加新字段。

可以读一下here in RavenDB Book 在修补文件下

即 以下 RQL 会将新字段 MyNewPropery 添加到 Categories 集合中的所有文档:

from Categories
update {
    this.MyNewPropery = "some content";
}

为了完成@Danielle 的回答,我认为为那些想要查找和更新旧文档的人添加这行代码会很有用。

where true and not exists(MyNewPropery)

It's a little weird command as you can see in where statement, but this is how we can use RQL to find not existed property in a certain collection.

完整代码:

from Categories
where true and not exists(MyNewPropery)
update {
    this.MyNewPropery = "";
}