Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1016

Mongo driver introduces new reserved field: "ok"

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.1.0
    • Affects Version/s: 2.1.0
    • Component/s: None
    • None
    • Major Change

      I'm preparing to move from Moped to the new official Ruby driver. I've noticed it accidentally introduces new reserved field name: "ok". This line checks if the first document returned from query contains key "ok" and that its value equals 1:

      https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/operation/result.rb#L208

      You can successfully create documents with that field, but if you set its value to anything other than 1 and later query the collection returning that document as the first result then you get OperationFailure error with a very unhelpful empty message.

      Attached are my test scripts. Here's the run log:

      mongoid-errors$ruby okey.rb 
      Using Mongoid 5.0.0.rc0
      Saved document #<MyDocument _id: 55e21bd24164617255000000, okey: true>
      Loaded: #<MyDocument _id: 55e21bd24164617255000000, okey: true>
      mongoid-errors$ruby also-okey.rb 
      Using Mongoid 5.0.0.rc0
      Saved document #<MyDocument _id: 55e21bd5416461725a000000, ok: 1>
      Loaded: #<MyDocument _id: 55e21bd5416461725a000000, ok: 1>
      mongoid-errors$ruby not-ok.rb 
      Using Mongoid 5.0.0.rc0
      Saved document #<MyDocument _id: 55e21bdc416461725f000000, ok: true>
      Mongo::Error::OperationFailure
      Operation failed. Here's the useless message:
      Message here >>  << end of message
      

      Please note that MongoDB documentation does not say anything about "ok" field. Here is the section on field name constraints:

      http://docs.mongodb.org/manual/core/document/#field-names

        1. okey.rb
          0.6 kB
        2. not-ok.rb
          0.5 kB
        3. also-okey.rb
          0.5 kB

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            amw Adam Wróbel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: