Adding an index to mongodb collection hash field with dynamic key values -
i m using mongoid , rails 4. have model has 'data' field of type hash. field store dynamic key value pairs. know can add indexing static fields possible add indexing keys of 'data' , how should done.
you can add in same way if index not in dynamic field, this:
class person field :data, type: hash index('data.foo' => 1) end
i pretty sure mongoid dont validate if fields exists, can create index on model. if dont have docs containing field, add sparse
option index, save space in memory.
Comments
Post a Comment