Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Atomic multi-location update #313

Closed
jericdeleon opened this issue Mar 15, 2017 · 8 comments
Closed

Atomic multi-location update #313

jericdeleon opened this issue Mar 15, 2017 · 8 comments

Comments

@jericdeleon
Copy link

Hi! Would it be difficult to add atomic multi-location updates as shown in this Firebase Blog post:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
// Generate a new push ID for the new post
var newPostRef = ref.child("posts").push();
var newPostKey = newPostRef.key();
// Create the data we want to update
var updatedUserData = {};
updatedUserData["user/posts/" + newPostKey] = true;
updatedUserData["posts/" + newPostKey] = {
  title: "New Post",
  content: "Here is my new post!"
};
// Do a deep-path update
ref.update(updatedUserData, function(error) {
  if (error) {
    console.log("Error updating data:", error);
  }
});

I can try my hand on a pull request (tbh wary, first-ever PR if so) but:

  1. should this plugin's firebase.update() be edited, or a separate method be instead stubbed out for multi-location updates (different parameter types in firebase.d.ts); and
  2. I'm not sure how to work/test out the iOS counterpart; I'm not that familiar with Obj-C
@davorpeic
Copy link
Contributor

Hi @lorcanfurey this is already working, just missing from the docs, check question and example from this issue #229

davor

@jericdeleon
Copy link
Author

Thanks for the heads up @davorpeic!

@anuragd7
Copy link

I just tried the atomic multi-location update. The behavior that I seem to be getting is a complete overwrite of the all the keys in the path specified. Is this the intended behavior? Since we are using update I thought only the value of the specified keys would be updated and the rest of the keys would remain unchanged.
@lorcanfurey , @davorpeic could you let me know if this is the behavior you observe?

Thanks

@jericdeleon
Copy link
Author

Just verified, I am also experiencing @anuragd7 's issue; all other fields at the intended path get nuked

Any ideas @davorpeic ?

@davorpeic
Copy link
Contributor

davorpeic commented Apr 19, 2017

Hey @anuragd7 and @lorcanfurey
I'm just checkin what firebase ios sdk docs say, and I see that the update method is identical to what Eddy is using, but it doesn't say anything on how the update/overwrite is done.

One possible workaround would be defining each field you want to update as separate update, and update it as a part of atomic update, that way you would actually update each individual field needed to be updated?

This is not tested, but I suppose it should work, can you try?

var companiesPath = 'companies/company_name';
var usersPath = 'users/user_nickname';

var data = {};
data[companiesPath] = 'Best Company Name';
data[usersPath] = 'John';

firebase.update('/', data);

dp

@anuragd7
Copy link

Hi @davorpeic, That's what I ended up doing and can confirm it works.👍

@EddyVerbruggen
Copy link
Owner

Thanks for this guys. If anyone is up for an update of the plugin docs I'd be happy to merge a PR.

@EddyVerbruggen
Copy link
Owner

Scrap that - that's exactly what @davorpeic has already done ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants