Blaine Lafreniere
Blaine Lafreniere

Reputation: 3610

How do you access a collection from the meteor shell?

I'm trying to execute this query in a meteor shell, I need to use the meteor shell because one of the query parameters is a moment object.

date = moment().subtract(5, 'hours').toDate()
return Messages.find {createdAt: {$gte: date}}

In meteor shell:

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

> Messages
ReferenceError: Messages is not defined

I have to run the code in the meteor shell because the query uses moment objects.

Upvotes: 4

Views: 1753

Answers (1)

MrITR
MrITR

Reputation: 31

I was able to do this by calling the following on the Meteor Shell:

MyCollection = Mongo.Collection.get("collectionName");

Replace "collectionName" with a string containing the name of the mongo db collection.

Also Mongo.Collection.getAll() to return all collections on the shell.

Upvotes: 3

Related Questions