0

I want to update a value under a certain key without using the "naive" way of copy/pasting the key value. Because I want it to scale to any client.

I basically want to update on click the "edit" property to "true".

Here's my current tree structure: enter image description here

My current method:

      var query= db.ref('Clients/AgenceEco/forms/step1/');
          query.update({
              edit: true
      })

The problem is that it actually adds an edit property under the "step1", like the following: enter image description here

I obviously don't want that but want to update the value under the random generated key of firebase.

How would you go about solving this issue? Thanks

1
  • How does this have anything to do with Vue specifically? Commented Nov 7, 2017 at 14:29

2 Answers 2

1

I think you can do this:

var updates = {};
updates['Clients/AgenceEco/forms/step1/edit'] = true;
db.ref().update(updates);

https://firebase.google.com/docs/database/admin/save-data#section-update

Edit: Regarding your comments you could do this (but I think there may be an easier way of doing it):

var ref = 'Clients/AgenceEco/forms/step1';
firebase.database().ref(ref).once('value', function(snapshot) {
    var data = snapshot.val();
    if (data) {
        data.edit = true;
        firebase.database().ref(ref).update(data);
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Hi Camden_kid...unforntunately this added a whole new tree with "Clients/AgenceEco/forms/step1/edit" under the unique id key -KyLgpQY1UShZELIgdOz
Any ideas on just targeting the "edit" property under that unique key? Thanks
@Tony If you have access to the key then it would be updates['Clients/AgenceEco/forms/step1/key/edit'] = true;, e.g. updates['Clients/AgenceEco/forms/step1/LyLgpQY1UShZELIgd0z/edit'] = true;
Thankss! In my case i don't have access to the key...would you know how to do that?
0

Just do that on child, not step1 directly. With child method:

var query= db.ref('Clients/AgenceEco/forms/step1/')
query.child().update({
  edit: true
})

1 Comment

Hi @WaldemarIce, unfortunately I get: "Reference.child failed: Was called with 0 arguments." I see what you're saying, but i cannot target that specific unique key under step1. Any ideas?

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.