I have a strange problem. Suppose I have a user model with only name
field.
I can add a field with value by creating an instance in mongodb rails
environment.
Example:
class User
include Mongoid::Document
field :name
end
Now in rails console, If you do
user = User.new
user[:name] = "xxxx"
user[:firstname] = "yyyy"
user.save
The record gets created with name and firstname fields. But i havent
declared firstname field in model.
I have a strange problem. Suppose I have a user model with only name
field.
I can add a field with value by creating an instance in mongodb rails
environment.
Example:
class User
include Mongoid::Document
field :name
end
Now in rails console, If you do
user = User.new
user[:name] = "xxxx"
user[:firstname] = "yyyy"
user.save
The record gets created with name and firstname fields. But i havent
declared firstname field in model.
Can anyone please help me out.
Mongodb records don't have a fixed schema - each document can store
arbitrary data. field :name just creates some convenient accessors for
you (and allows you to do things like say that a certain field is
required etc). See http://mongoid.org/docs/documents/dynamic.html