I have a job that create new fields to my document, I want, at the end of this job, to create indexes to this fields. I tried
Model.index("field"=>-1)
and also
Mongoid::Sessions.default[:rating_prediction].ensureIndex
Without success
Is this possible?
Saying
Model.index(:field => -1)
, more or less, just registers the existence of the index withModel
, it doesn't actually create an index. You're looking forcreate_indexes
:So you'd want to say:
You can also create them directly through Moped by calling
create
on the collection'sindexes
:Mongoid::Sessions
has been renamed toMongoid::Clients
in newer versions so you might need to say:Thanks to js_ for noting this change.