1

I have multiple documents in a RavenDB NoSql database. I'm using restful services to post, put and get the Team documents when needed. However, I need to create functionality to type a string and loop through all the documents splicing out that specific string from the document as it goes through each document. My JSON format is as such.

{
"Name": " Management Team Lead",
"IsActive": true,
"UserRoleId": "userRoles/DemoSystemAdmin",
"Region": "Europe",
"Country": "Unknown",
"CommitteeType": "Haaa",
"MemberUserIds": [
    "joeBlogs",
    "TomCreen",
    "Herbyvoire",
    "MayJune",
],
"PortfolioIds": [],
"LegalEntityIds": []

}

In this case I have to check 40+ plus team documents if a MemberUserId exists in that Team document and if so remove it. I'm very new to .Net but I imagine what I'll be trying to do is loop "Get" each document, then check to see if the string matches the Json and if it does splice in a blank and "Put" back to database.

How do I go about looping through each document without having to specify the name of each?

1
  • Surely RavenDB allows you to query only the records that contain the value you are looking for? Commented Apr 26, 2018 at 14:01

1 Answer 1

1

Using RQL, you can do this with the following query:

from Users as u
where u.MemberUserIds[] = 'TomCreen'
update {
    u.MemberUserIds = u.MemberUserIds.filter(m => m != 'TomCreen')
}

This will both find only the relevant documents and update them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.