【发布时间】:2016-04-18 17:16:50
【问题描述】:
我的模型中有一个 ruby 方法。我正在生产中测试该方法,并希望在 MongoDB shell 中运行该方法。运行模型中的 ruby 方法的语法是什么。这是我的方法。
Coupon.rb
def self.get(code)
where(
:code => (normalize_code(code)),
:$and => [
{
:$or => [
{ :coupon_count.gte => 1 },
{ :coupon_count => nil }
]
}, {
:$or => [
{ :expires_at.gte => Date.today },
{ :expires_at => nil }
]
}
]
).first
end
我似乎找不到在 MongoDB Shell 中运行此方法的方法。
【问题讨论】:
-
从 Rails 控制台运行
normalize_code并将结果粘贴到 MongoDB shell 中。或者在 JavaScript 中实现normalize_code,以便您可以在 MongoDB shell 中运行它。
标签: ruby-on-rails ruby mongodb shell