Pergunta

Following query is running in MongoDB console correctly,

> db.venues.find({'location.region_id':ObjectId("533e67246d696e1279170000")}).count()
8

But when i write the same query in rails using mongoid its not showing anything, the query is as follows,

<%= Venue.where({'location.region_id' => '533e67246d696e1279170000'}).count %>

I don't know what's wrong with my query.

Foi útil?

Solução

Convert the id to an ObjectId object:

<%= Venue.where({'location.region_id' => BSON::ObjectId.from_string('533e67246d696e1279170000')}).count %>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top