【问题标题】:How do you access a collection from the meteor shell?您如何从流星外壳访问集合?
【发布时间】:2015-04-28 08:16:37
【问题描述】:

我正在尝试在流星外壳中执行此查询,我需要使用流星外壳,因为查询参数之一是矩对象。

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


    【解决方案1】:

    我可以通过在 Meteor Shell 上调用以下命令来做到这一点:

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

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

    也可以Mongo.Collection.getAll() 返回 shell 上的所有集合。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 2016-07-29
    • 2016-07-17
    • 2017-02-10
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    相关资源
    最近更新 更多