Reputation: 21791
I'm using mongomatic gem
Here's a list of indices:
Address.collection.index_information #=>
{"_id_"=>
{"v"=>1, "key"=>{"_id"=>1}, "ns"=>"downloader_test.proxies", "name"=>"_id_"},
"address_1"=>
{"v"=>1,
"key"=>{"address"=>1},
"unique"=>true,
"ns"=>"downloader_test.proxies",
"name"=>"address_1"},
"randomizer_1"=>
{"v"=>1,
"key"=>{"randomizer"=>1},
"ns"=>"downloader_test.proxies",
"name"=>"randomizer_1",
"2d"=>true}}
When I'm trying to use $near operator in query i got such error:
Address.collection.find_one('randomizer' => { '$near' => [129, 0] }) #=>
Mongo::OperationFailure: can't find any special indices: 2d (needs index),
2dsphere (needs index)
I can't understand why it doesn't work, it has index for randomizer but can't use it.
What might be a problem?
Upvotes: 0
Views: 163
Reputation: 1858
This also happens when your values for the location array are imported as strings instead of floats. Make sure your seeds come in with .to_f or that you're not setting the values as strings.
Upvotes: 1
Reputation: 21791
The problem was with setting up the index
Instead of
Address.collection.create_index("randomizer", '2d' => true)
should be as
Address.collection.create_index("randomizer" => '2d')
Upvotes: 0