meteor-astronomy icon indicating copy to clipboard operation
meteor-astronomy copied to clipboard

Collection functions not working on astronomy objects

Open lensKamdem opened this issue 7 years ago • 6 comments
trafficstars

I am using astronomy v2.5.6, when use a collection function like find or update on an astronomy class instance eg. User.find(), i get the error:

TypeError: User.find() is not a function

Any clue guys? Even v2.5.3 i got the same error

lensKamdem avatar Mar 14 '18 18:03 lensKamdem

@lensKamdem does the User class have the collection property provided? If not, then class will not have the find, update etc. methods as they are only intended to work on collections.

lukejagodzinski avatar Mar 14 '18 19:03 lukejagodzinski

@lukejagodzinski I did not add any collection property, but in the documentation it is said that find, findOne, update etc. methods work on astronomy classes. If i need to add them myself, how do i go about?

lensKamdem avatar Mar 15 '18 10:03 lensKamdem

Everything is described in docs.

import { Class } from 'meteor/jagi:astronomy';
import { Mongo } from 'meteor/mongo';

const Users = new Mongo.Collection('users');
const User = Class.create({
  name: 'User',
  collection: Users // YOU HAVE TO PROVIDE COLLECTION HERE
});

lukejagodzinski avatar Mar 15 '18 11:03 lukejagodzinski

@lukejagodzinski i did it. When a set a property with the set() and then save it, it is normally inserted into the Mongodb collection, that is find. But when i try to use findOne or update, there is an error telling me the method is not function!

lensKamdem avatar Mar 15 '18 11:03 lensKamdem

Then create reproduction repository because there is probably error in your code. You can also take a look at the example app to see how to use Astronomy https://github.com/jagi/meteor-astronomy-examples

lukejagodzinski avatar Mar 15 '18 11:03 lukejagodzinski

I will try it

lensKamdem avatar Mar 15 '18 11:03 lensKamdem