Can't seem to access objects reliably from meteor shell


I have some code that I’m trying to run in the meteor shell, because it doesn’t seem to be working in my app, so I’d like to confirm that it works on the shell, outside of my app.

The code I’m trying to isolate is:

  Meteor.publish "messageData", () ->
    date = moment().subtract(5, 'hours').toDate()
    return Messages.find {createdAt: {$gte: date}}

I need to use the meteor shell because of the use of the moment object.

When I load up the meteor shell, it seems to be hit or miss as to whether either ‘moment’ or ‘messages’ is loaded. Sometimes none of those two are loaded, sometimes one, I have yet to see both accessible at the same time.

I wish I had more information to provide, but I’ve been restarting the meteor server and the meteor shell over and over again, and it’s really exactly that, sometimes moment is what I expect it to be, sometimes it’s undefined. Sometimes the Messages collection is what I expected it to be, other times it’s undefined.

If I attempt to define the collection, I get:

> Messages = new Mongo.Collection("messages")
Error: A method named '/messages/insert' is already defined


I’ve restarted the meteor server and the meteor shell several times again now, and miraculously, I was able to access both the collection I’m referring to above, and the moment object simultaneously… and then after closing the shell and opening it again… they were both gone, no longer accessible.


Both me and @delgermurun have experienced the same problem (moment not being defined). In my case it seemed to come from having both momentjs:moment and mrt:moment installed.

In @delgermurun’s case, I think it was fixed by removing and adding the moment package again. Weird stuff…


Ultimately what I ended up doing was storing my timestamps as unix timestamps, to make it easier to work with outside of my app.