Xaimaran
Xaimaran

Reputation: 413

RavenDb add property using RQL

Is there a way to add a property to all documents in a collection using 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.

Upvotes: 2

Views: 323

Answers (2)

Xaimaran
Xaimaran

Reputation: 413

To complete @Danielle answer, I thought it would be useful to add this line of code for those who wants to find and update their old documents.

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.

Complete code:

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

Upvotes: 1

Danielle
Danielle

Reputation: 3839

You can add a new field with Patching.

Can read about it here in RavenDB Book Under Patching Documents

i.e. The following RQL will add the new field MyNewPropery to all documents in the Categories collection:

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

Upvotes: 1

Related Questions