Reputation: 2858
I'm getting something incredibly simple wrong, and not sure what I'm doing wrong. Fairly new to Mongo
Using Rails 3.2.6 with MongoDB and Mongoid. Trying to add an index to an embedded field.
I have a model 'Scheme', which has embedded 'Referals'. "Referal" has a field 'to_code' (string). I want to index this field.
class Scheme
include Mongoid::Document
include Mongoid::Timestamps
embeds_many :referals
index "referals.to_code" => 1
class Referal
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :scheme
when I run 'rake db:mongoid:create_indexes' this fails with this error:
Not a Mongoid parent model: app/models/referal.rb
rake aborted!
Invalid index specification {"referals.to_code"=>1}; should be either a string, symbol, or an array of arrays.
As far as I can tell this follows the Mongoid documentation exactly, so not sure what I'm doing wrong. Any help much appreciated.
Upvotes: 2
Views: 1836
Reputation: 8388
I think you are using mongoid 3 syntax with version 2 of the gem.
The error message indicates that the mongoid 2 index syntax is expected: http://two.mongoid.org/docs/indexing.html
You are trying to use the mongoid 3 index syntax: http://mongoid.org/en/mongoid/docs/indexing.html
Check what version of the gem you are using and adjust your syntax accordingly.
Upvotes: 3