Search code examples
sqldatabaseravendb

How to insert update a document in RavenDB Studio (RQL)


I have an assigment on ravenDb and I've written queries for selecting, sorting, filtering and such. But I cannot figure out how to do simple adding a new document to a collection named "Employees" or updating a value inside document "employees/8-A", from "employees".

I have gone through the documention using these links:

https://ravendb.net/docs/article-page/5.4/csharp/client-api/operations/patching/set-based https://ravendb.net/docs/article-page/5.4/csharp/client-api/operations/patching/single-document

I even googled and came across this thread ; Updating documents in RavenDB But one of the linked articles is deleted.

But it's just JS code. Is there no syntax I can run inside the query tool in raven db studio?


Solution

  • For managing updates from the Session, Look at the following demos:

    Adding/creating a new document:
    https://demo.ravendb.net/demos/csharp/basics/create-document
    Load and edit document:
    https://demo.ravendb.net/demos/csharp/basics/load-and-edit-document


    For updating a field with Patching, from all docs, see the inner RQL for example here:
    https://ravendb.net/docs/article-page/5.4/csharp/client-api/operations/patching/set-based#updating-by-document-id-using-parameters

    from @all_docs as d
    where id() in ($ids)
    update { d.Updated = true; }
    

    Or, from a specific collection:

    from Companies
    update { this.Name = 'newName'; }
    

    Learn also about Patching here:
    https://ravendb.net/learn/inside-ravendb-book/reader/4.0/4-deep-dive-into-the-ravendb-client-api#patching-documents-and-concurrent-modifications