我的模型中有一個ruby方法。我正在測試生產中的方法,並希望在MongoDB shell中運行該方法。運行模型中的ruby方法的語法是什麼?這是我的方法。在MongoDB shell中運行ROR模型方法
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中運行它。 –