0

I am trying to make an extremely simple Meteor app that is almost exactly the same as the tutorial. I am simply trying to return all the elements from a collection. I am using autopublish.

My code looks like this. I am using coffeescript, but I tried using JavaScript and there was no change.

    @Studies = new Mongo.Collection "studies"

    if Meteor.isClient
        console.log "Is client"
        Template.find.helpers
            studies: ->
                console.log "client"
                console.log Studies.find().fetch()
                return Studies.find()

When I load the page, "client" is logged and "[]" is logged after. However, when I run mongo in terminal, I run "db.studies.find()" and what is returned is

    { "_id" : ObjectId("56601b66ab1ba5a30d2d94c7"), "title" : "study 1" }

What am I doing wrong? I really appreciate your help in advance, as I have been stuck on this for hours now.

jeffjc97
  • 63
  • 9
  • Maybe this anwer can help you in the good direction: http://stackoverflow.com/a/28891421/4278038 – McVenco Dec 03 '15 at 10:53
  • Thanks for the response! However, I am using autopublish so there shouldn't be an issue with publishing. – jeffjc97 Dec 03 '15 at 10:55
  • Still, it's probably caused because the code is running too early (before the autopublish has completed). Another related question/answer: http://stackoverflow.com/a/20210212/4278038 – McVenco Dec 03 '15 at 11:04
  • I tried logging count in the code and after the site loaded. Both times, it returned 0. I think that means that the timing isn't the issue here, and there's something else that's wrong. What do you think? – jeffjc97 Dec 03 '15 at 11:12
  • Well, if you are sure you have `autopublish` and some data in the collection... it should work. Could you please create a [MeteorPad](http://meteorpad.com/) to demonstrate your issue? – Kyll Dec 03 '15 at 11:45
  • @McVenco it would surely run before publish completed, but it would also rerun when data would be available – sdooo Dec 03 '15 at 13:41
  • You inserted the values using the mongo prompt, and now they have `ObjectId`s for an `_id`. Try to use the server shell (`meteor shell`) to insert the documents and see if that helps. See [this answer](http://stackoverflow.com/a/33971972/268093) for more details. – MasterAM Dec 03 '15 at 15:11
  • @MasterAM Thank you so much!!!! I used the shell and inserting it worked! Thanks to everyone else as well! – jeffjc97 Dec 03 '15 at 19:10

0 Answers0