Erich Oliveira
Erich Oliveira

Reputation: 56

Find on meteor client don't work

I'm trying to do a pretty basic example using meteor js. In my lib folder (shared by client and server) i have the following code

if (typeof hair === 'undefined') {
    hair = {};
}
if (!hair.dao) {
    hair.dao = {};
}

hair.dao.store = (function() {
    return new Meteor.Collection('store');
})();

In folder server/libs i have this code

Meteor.startup(function() {
    console.log(hair.dao.store.find().fetch());
});

(Which log one element)

In my client/libs folder i have this code

var cursorStores;
cursorStores = hair.dao.store.find();
console.log(cursorStores.fetch());

(Which logs no element)

It used to work, but now it stops.

Just to be clear i'm running on windows, and i removed and added again the autopublish package.

Upvotes: 0

Views: 91

Answers (2)

penner
penner

Reputation: 2737

I think find needs to take an argument. See http://docs.meteor.com/#find

If you are wanting the first element there are other ways of getting it. http://docs.meteor.com/

Try find({}) with empty curly braces

Upvotes: 1

matb33
matb33

Reputation: 2820

The data probably hasn't reached the client yet when you do that find. Try wrapping those 3 lines of client code in a Deps.autorun

Upvotes: 1

Related Questions