step-up-labs / firebase-database-dotnet

C# library for Firebase Realtime Database.
MIT License
668 stars 168 forks source link

Attempt to Update just the file location #277

Closed eduardoagr closed 2 years ago

eduardoagr commented 2 years ago

I have a child Notes, and I want to update just the file location

`public async void UpdateNotebookNote(string Id, string FileLocation) {

        await firebaseClient
            .Child(AppConstant.Notes)
            .Child(Id)
            .PatchAsync(FileLocation);
    }`

but when I do this, I get this exception

`public async void UpdateNotebookNote(string Id, string FileLocation) {

        await firebaseClient
            .Child(AppConstant.Notes)
            .Child(Id)
            .PatchAsync(FileLocation);
    }`
cabauman commented 2 years ago

You didn't include the exception (looks like a copy/paste mistake). And you didn't include any details about your db structure (e.g. what properties the Note object has).

eduardoagr commented 2 years ago

Sorry @cabauman

this is mt database structure

"Notebooks" : { "-MxdwMGbOdhmL85JoX9K" : { "Color" : "#FF008000", "CreatedDate" : "Tuesday, March 8, 2022", "Name" : "NOTEBOOK", "UserID" : "4B7L4mRordT2s373NCwgNLesxj13" } }, "Notes" : { "-MxepAH9BW0Uv065a5LR" : { "FileLocation" : "", "Name" : "ed", "NotebookId" : "-MxdwMGbOdhmL85JoX9K" } } }

this is how I am trying to update

` await firebaseClient .Child(AppConstant.Notes) .Child(Id) .PatchAsync(FileLocation); }``

Exception

Firebase.Database.FirebaseException: 'Exception occured while processing the request. Url: https://duonotes-f2b77-default-rtdb.europe-west1.firebasedatabase.app/Notes/-MxepAH9BW0Uv065a5LR/.json?print=silent Request Data: https://notesbucket.blob.core.windows.net/notes/ed.html Response: { "error" : "Invalid data; couldn't parse JSON object. Are you sending a JSON object with valid key names?" } '

Xamarin forms 5.0 Android version 11 Windows 11 Visual studio 2022 Comunity

cabauman commented 2 years ago

One more question.

.PatchAsync(FileLocation);

Is FileLocation a string?

eduardoagr commented 2 years ago

@cabauman yes it is

cabauman commented 2 years ago

Patch needs an object:

.PatchAsync($"{{ \"FileLocation\" : \"{FileLocation}\" }}");
eduardoagr commented 2 years ago

why do I have to put \

cabauman commented 2 years ago

It's json so we have to escape the quotes. I hope it helped.

eduardoagr commented 2 years ago

yes thank you @cabauman