Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created June 3, 2013 23:19
Show Gist options
  • Select an option

  • Save jwoertink/5702300 to your computer and use it in GitHub Desktop.

Select an option

Save jwoertink/5702300 to your computer and use it in GitHub Desktop.
What is the best way to index this in MongoDB? Even more so, what is the best way to index this with mongoid in rails?
{
"$or" => [{"receivers"=>"5149fb21d863673f0f000001"}, {"actor_id"=>"5149fb21d863673f0f000001"}],
"_id" => {"$ne" => "51a91dd4d8636716cc000015"},
"created_at" => {"$gt" => 2013-05-31 22:01:56 UTC},
"action" => {"$nin" => [:comment, :favorite]},
"object_type" => {"$nin" => ["User"]}
}
#mongoid model
class Activity
# stuff
# How do I index that query?
index {receivers: 1, actor_id: 1, created_at: 1, action: 1, object_type: 1}
# mode stuff
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment