-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
[2.0] observeSource API / docs confusing #183
Comments
what problem are you trying to solve? If you have data added by the user in offline mode you could do something like: const fooRemote = new Mongo.Collection('foo');
const foo = new Ground.Collection('foo');
foo.observeSource(fooRemote.find());
Meteor.subscribe('foo', () => {
// keep only current sub and data added offline
foo.keep(fooRemote.find(), foo.find({ addedOffline: true }));
foo.find({ addedOffline: true }).forEach((doc) => {
// add the document to the remote db?
fooRemote.insert(_.omit(doc, 'addedOffline'));
});
}); |
For this particular collection I'm just trying to keep a mirror offline. And that is what I had assumed const OrgProfiles = new Mongo.Collection('orgProfiles')
const OrgProfilesMirror = new Ground.Collection('orgProfilesMirror')
Tracker.autorun(() => {
const subscription = Meteor.subscribe('orgProfiles.selectionList')
if (subscription.ready()) {
const orgProfilesCursor = OrgProfiles.find()
OrgProfilesMirror.keep(orgProfilesCursor)
OrgProfilesMirror.observeSource(orgProfilesCursor)
}
} So wondering if there should be a method to do this (which could probably be more efficient that what I have here). |
const OrgProfiles = new Mongo.Collection('orgProfiles')
const OrgProfilesMirror = new Ground.Collection('orgProfilesMirror')
OrgProfilesMirror.observeSource(orgProfiles.find())
const subscription = Meteor.subscribe('orgProfiles.selectionList')
Tracker.autorun((c) => {
if (subscription.ready()) {
c.stop();
OrgProfilesMirror.keep(OrgProfiles.find())
}
} |
Thanks. I see. And this is efficient in terms of access to the storage as To avoid opening another issue for a question. When |
Sure we could add an option eg. "ForceImmutable"? |
That would be perfect. |
We too are considering GroundDB for this use case. |
I had assumed that
observeSource
would make the GroundDB collection match the collection it was observing. But that doesn't appear to be the case. I think I need to callkeep
first to make the collections match and thenobserveSource
to keep it up to date, otherwise old records might be lying around in the GroundDB collection.I can understand the need for both cases. Should there be a different method or some options to choose to leave records not matching the cursor?
Combining these two steps could also be more efficient since at the moment
observeSource
will run through all the existing docs again to do the initialadded
just afterkeep
has. If there was a combined call then_suppress_initial
could be used and the existing docs updated while calculating the ones to remove.The text was updated successfully, but these errors were encountered: