Considering the following database document:

I need push an element to array highlighted field “Roles”.
I’ve tried the code below but without success. I need to know which command use in place of “SelectWhere”…
patches.Add(new ScriptedPatchCommandData
{
Key = "Users/" + (mp.EnableChangeUserName ? user.ProviderUserKey : username),
Patch = new ScriptedPatchRequest
{
Script = @"
var app = this.Applications.SelectWhere(function(application){
return application.Key == appKey;
});
if(app != null) { app.Roles.PushAll(roles) }",
Values = { { "appKey", mp.ApplicationKey }, {"roles", roleNames} }
}
});
Suggestions?
This should do the trick:
When testing in the Raven Management Studio, It seems that you can’t represent an array in the Parameters window, so I had to enter it as a string
["foo","bar"]and make one minor change to the script: