Skip to content
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

Unclear on how to use version 2 #198

Closed
MastaBaba opened this issue Jun 6, 2017 · 2 comments
Closed

Unclear on how to use version 2 #198

MastaBaba opened this issue Jun 6, 2017 · 2 comments
Labels

Comments

@MastaBaba
Copy link

I'm not clear on how I can get ground:db 2 to work. The version that's on Atmosphere works for me, to the extent that not all my grounded collections have persistency. I very much want to move to the current release candidate. However, I can not get it to work.

So, how to set up ground:db in its current version?

Below is what I understand.

In, say, /imports/api/ I define the collections that need publishing, so, e.g.

Cities = new Ground.Collection('cities');

if (Meteor.isServer) {
	Meteor.publish('cities', function citiesPublication() {
		return Cities.find();
	});
}

In /server/main.js, I include the above, like so:

import '../imports/api/cities.js'

I should now be able to manipulate Cities in /server/main.js.

In /client/main.js, I want to have a grounded version of Cities. For example, like so:

Meteor.startup(function () {
    GroundedCities = new Ground.Collection('groundedCities');
    GroundedCities.observeSource(Cities.find());
});

However, now, querying GroundedCities (for example with GroundedCities.find().fetch()) generates a client side error, as if the collection is not defined.
How to resolve this?

Additionally, any methods for Cities are not defined for GroundedCities. So, does this imply that I should write my code such that, on the client, writes are performed on Cities, while reads are performed on GroundedCities?
Does that mean the client also needs to subscribe to Cities, besides GroundedCities having been defined, client-side?

@s7dhansh
Copy link

Ground is only available to you on the client. You should use Meteor.Collection everywhere in general. Ground.Collection should be used only to instantiate grounddb collections on client after which you will need to use .observeSource and .keep.

Example:

Cities = new Meteor.Collection('cities');

if (Meteor.isClient) {
	GDCities = new Ground.Collection('local.users');
	GDCities.users.observeSource(Cities.find());
        Meteor.subscribe('cities', {
             onReady() {
                   GDCities.keep(Cities.find({}, {reactive: false}));
             }
       });
       GDCities.once('loaded', () => { console.log('loaded'); });
}

@ghost
Copy link

ghost commented Mar 28, 2018

This really should be the first page of the readme lol

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

No branches or pull requests

3 participants