-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync issue when tampering with local collections in MiniMongo #568
Comments
For now the best way of doing it is reloading a document |
Bumped into this issue again: Calling This would be awesome: onChange: (value) => {
Docs._collection.update({
_id: docId
}, {
$set: {
distance: value // on last call to onChange, value is 0
}
});
},
onEnd: (value) => {
doc.distance = value; // value is still 0
doc.save({ fields: ['distance'], forceUpdate: true }); // value gets updated due to forceUpdate-flag
} |
Can you make reproduction repository because I don't quite understand your problem |
Sure, I'll provide a repro, but just in case, here's a more thorough explanation: Imagine my app has a slider component. Slider can have values between 0 ... 100. Whatever value it's set at will be saved to a document on database, but I also want to reflect the change in real time on the page. That's what the While the slider is being slided, to prevent my DB from being bombarded with calls, I'm actually updating the local collection: After the slider is released, The problem is, Astronomy thinks it doesn't need to update the value to database, because I tampered with the local collection on client (new value is same as old value, or so Astronomy thinks!). So, to overcome this...I now have to do something like this: onEnd: (value) => {
const WHATEVER_MADEUP_VALUE_THAT_IT_CANNOT_ACTUALLY_BE = -1;
Docs._collection.update({
_id: doc._id
}, {
$set: {
distance: WHATEVER_MADEUP_VALUE_THAT_IT_CANNOT_ACTUALLY_BE
}
});
doc.distance = value;
doc.save({ fields: ['distance'] });
} |
Ok, now I see what is the problem. You're not doing it correctly. First, you shouldn't modify private |
I do acknowledge there are many ways to implement the scenario explained above with Meteor, some more correct than others :) I'm using a local collection myself in the case I described since Astronomy doesn't have the For example, I can never be 100% sure my collection on client is up to date, but sometimes I want to make sure a change is persisted to DB. |
Yep, such a feature might be handy in some scenarios. Maybe I will implement it next week if I have time for that :) |
Fixed it in version 2.5.2. Now you can write |
Sometimes a developer might wish to update the local MiniMongo collection, for example with a high frequency user interaction such as dragging and updating coordinates.
and then, once this high frequency user interaction is complete, update the final value to database.
At this point, calling
document.save()
does nothing, and I presume it is because Astronomy thinks the value hasn't changed?What about providing an option to "force" the update, like
doc.save({ force: true })
?The text was updated successfully, but these errors were encountered: