-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.0.0 final
-
Component/s: Attributes
-
None
-
Environment:Ruby on Rails
I can create fields with special characters directly in MongoDB as shown below:
db.createCollection('something_random')
use something_random
db.something_random.insertOne( { 'hello 22 all is ..' : 'hello' })
> db.something_random.find()
{ "_id" : ObjectId("5c3a4d8b66ac463c10761e43"), "hello 22 all is .." : "hello" }
Notice directly in MongoDB I am able to create a field called "hello 22 all is ..". Now when I try to do the following in Mongoid, look what happens:
class Test3
include Mongoid::Document
include Mongoid::Attributes::Dynamic
end
t3 = Test3.new
t3.write_attribute(:'hello world.. ~', 'hi')
NoMethodError: undefined method `[]' for nil:NilClass
from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/extensions/hash.rb:104:in `block in _nested'from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/extensions/hash.rb:104:in `block in __nested' from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/extensions/hash.rb:103:in `each' from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/extensions/hash.rb:103:in `nested_' from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/attributes.rb:100:in `read_attribute' from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/changeable.rb:232:in `attribute_will_change!' from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/attributes.rb:176:in `block in write_attribute' from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/threaded/lifecycle.rb:26:in `_assigning' from /home/merlino/.rvm/gems/ruby-2.1.2@merlino/gems/mongoid-4.0.2/lib/mongoid/attributes.rb:170:in `write_attribute' from (irb):42
Why do I get this error and if it is not possible to create such a field with special characters in Mongoid as it is in MongoDB, can anyone recommend how I can take on such a task? I do not mind to contribute the source code I create to the project if it will extend it.
- related to
-
RUBY-1092 Add option to check keys in BSON and provide configurable option in driver
- Closed