如何在 Meteor Shell 中访问集合?

4

我正在尝试在meteor shell中执行这个查询,我需要使用meteor shell,因为查询参数之一是一个moment对象。

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

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

> Messages
ReferenceError: Messages is not defined

我需要在meteor shell中运行代码,因为查询使用moment对象。
1个回答

3
我可以通过在 Meteor Shell 上调用以下内容来实现这一点:
MyCollection = Mongo.Collection.get("collectionName");

将"collectionName"替换为包含mongo db集合名称的字符串。

还可以使用Mongo.Collection.getAll()在shell上返回所有集合。


2
为了使其正常工作,您可能需要确保安装了此软件包:https://github.com/dburles/mongo-collection-instances - Matt Schlobohm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接