-
Notifications
You must be signed in to change notification settings - Fork 80
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
How to synced data between same collection in different cluster (main app and search app)? #15
Comments
There are couple of ways, you can do it. Easy wayUse the same database for the both apps Other wayLet's say you wan't connect to the // web app
Meteor.publish('myPosts', function(category) {
return Posts.find({category: category});
}); Now, from the search service do this. // in search app
var webAppConn = Cluster.discoverConnection('web');
webAppConn.subscribe('myPosts', 'my-category');
var Posts = new Mongo.Collection('posts', webAppConn);
// access data
console.log(Posts.find().fetch()) |
Hi @arunoda Thanks |
Sorry another question, from your example, how if I am inserting data from search app? How to sync them? Or just using manual webservice insert call, and manual inserting to search app collections? or are there any good solution? Thanks |
If you are using the same database, then you can simply do an insert as On Tue Feb 17 2015 at 2:24:53 PM Ega Wachid Radiegtya <
|
Hi @arunoda I think the answer should be manual call webservice insert. But after insert the data will be synced because of this (var Posts = new Mongo.Collection('posts', webAppConn);) right? Thanks for the answer |
Yes. for sure. On Tue Feb 17 2015 at 2:46:08 PM Ega Wachid Radiegtya <
|
Hi @arunoda, I have tried Your solution with simple code. I made two app, online and offline. I want my offline and online app are stand alone. But when I am using cluster, my app whether offline and online are having same display (which is offline display). Here are my codes:
Regards & Thanks |
Okay. Here's the case. Only it can have the UI stuff. Other are just exposing DDP apis. |
Sorry I mean the offline are web. And when I am changing to "web" the display within localhost:3000 and localhost:4000 will be same. (btw I had changed the code above) |
Yes. That's true. When the offline became the "web". If you visit any of the app, you'll get the UI of the web UI. That's the idea of the cluster. |
Oh I see, so in my case. It was incorrect if I choose cluster. Btw this is working when I am changing the cluster to normal DDP. Thanks for the answer @arunoda |
Yes. I will consider something like this in the future.
|
Ok @arunoda. I will building something like core banking app. So I need the offline version for internal bank use. And the online version for customer access their balance etc. So I need offline version database and online version database. Both of them can share data. While offline connection are down, the app are still able to use the online connection vice versa. For now I am still using DDP at online version to be connected to collection in offline version. When offline connection are down, the online db are using GroundDB to save it's state in local storage. When the offline connection are open again, the local storage from online version are synced to offline storage. Regards |
Okay. I got. May be we need to have more UI services in a cluster. I will
|
Cool, Thanks @arunoda |
Hi, I released a new version with now you can have many UIs. If you need more info, check the docs. |
Now the UI are able to be viewed in each app. But I can't get the collection in my second app (empty array result). here are the code:
Any Solutions? |
Yes. it seems like. Let's try to fix it. On Wed Feb 18 2015 at 1:20:00 PM Ega Wachid Radiegtya <
|
I've a fix. I'm working on it now. On Wed Feb 18 2015 at 1:47:46 PM Arunoda Susiripala <
|
Okay now check with the new version. if (Meteor.isServer) {
Cluster.connect("mongodb://localhost:27017/discovery");
Cluster.register("online");
var offlineConn = Cluster.discoverConnection('web');
var Posts = new Mongo.Collection('posts', offlineConn);
offlineConn.subscribe('posts', function() {
console.log(Posts.find().fetch());
});
} |
It work like charm although I don't use this offlineConn.subscribe('posts', function() { But I have another question in mind, sorry about too many asking :D. |
Actually, Todo that first, you need to call |
When I am trying to place Cluster.discoverConnection('web') on client, it said "no such endpoint". |
Yes. You need to do this |
I am also have doing that :D. but still no luck |
If possible, send me a sample repo. On Wed Feb 18 2015 at 3:17:45 PM Ega Wachid Radiegtya <
|
Here I made simple code repo, I decided to just using Search Packages of Yours. https://github.com/radiegtya/cluster-online-offline Please check it out :) |
Thanks. I'll go through this and ping you. On Wed Feb 18 2015 at 3:59:49 PM Ega Wachid Radiegtya <
|
Btw the problem now was I can't show the Posts data from the online app when using SearcSource package. Thanks @arunoda |
Hi @arunoda, btw I have solved the code. The app is now synced and able to show the data. I am forget to adding PostsSearch.search("text") when template rendered. Nah, the problem now is the data is not realtime/reactive. Is it possible to make SearchSource package being realtime (I think it's impossible because search source are running on server)? Thanks |
Nope, search-source is not realtime. May be you need to poll for changes On Fri Feb 20 2015 at 9:40:19 AM Ega Wachid Radiegtya <
|
Can You give me link about poll change in meteor? and one another question (it's maybe out of the topic, but still related to meteor cluster) If You think I should ask this in another place, I'll move this :) |
Btw How if I am removing my packages data from my main app collections? With this tutorial the data will be not synced between "packages collection" in main app and search app. I think it will be an issue. How to get it work (I mean the data between all collections are remain same/synced)? Thanks
The text was updated successfully, but these errors were encountered: