Mongoid에서 내 그룹화를위한 조건을 제공하고 싶지만 조건 해시의 속성에 대해 여러 값을 보내려면 어떻게해야합니까? 이것은 내가하고 싶은 것입니다 다음 중 하나를 page_id
에 따라서 그러므로Mongoid`group()`조건
PageViews.collection.group(
cond: {page_id: ['4e6912618083ab383e000010', '4e6912618083ab383e000009']},
key: 'timestamp',
initial: {count: 0},
reduce: "function(x, y) {y.count += x.count;}"
)
어떤 PageView
떨어져 쿼리 수 있지만 난 전혀 작동 조건 해시 (cond
)를 얻을 수없는 것! 나는 여기서 무엇을 잘못하고 있는지, 나는 정말로 혼란 스럽다. 어떤 도움을 크게 감상 할 수 http://api.mongodb.org/ruby/current/Mongo/Collection.html#group-instance_method
: 여기
는group()
방법에 대한 API 문서입니다.
PageViews.collection.group(
cond: {page_id: { $in : ['4e6912618083ab383e000010', '4e6912618083ab383e000009']}},
key: 'timestamp',
initial: {count: 0},
reduce: "function(x, y) {y.count += x.count;}"
)
다음과 같은 오류를 반환하지만, 구문이 나에게 잘 보이는 :
갱신
같은 쿼리를 실행하면
SyntaxError: (irb):170: syntax error, unexpected ':', expecting tASSOC
cond: {page_id: { $in : ['4e6912618083ab383e000010',...
^
(irb):170: syntax error, unexpected '}', expecting $end
...', '4e6912618083ab383e000009']}},
... ^
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
그것은 그 실망 이 곳 어디에도 예제가없는 것처럼, 문서에서는 t 그는 조건 매개 변수는 다음과 같은 수 있습니다 :
(String, BSON::Code) :cond — default: {} — A document specifying a query for filtering the documents over which the aggregation is run (optional).
그것이 String
또는 BSON::Code
, 어떤이의 모습 소요 그렇다면?
흠, 나에게 구문 오류 줄 것으로 보인다 구문 오류, 예기치 않은 '}'를, $ end expecting $ ... ','4e6912618083ab383e000009 ']}}, ...' –
여는 괄호를'page_id :'와'$ in' 사이에 넣었습니까? – Russell
도움을 많이 주셔서 감사 드리며, 제 질문은 어떻게 되나요? –