Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major - P3 Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.5
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL
    • # Replies:
      16
    • Last comment by Customer:
      true

      Description

      I can save a key with a "dot" using the latest Java client.

      This should not be allowed.

      import com.mongodb.Mongo;
      import com.mongodb.DBCollection;
      import com.mongodb.BasicDBObject;
      import com.mongodb.DB;
      
      public class Test {
      
          public static void main(String[] args) throws Exception {
      
              Mongo m = new Mongo();
              DB db = m.getDB("test_db_1");
              DBCollection coll = db.getCollection("test_collection_1");
      
              BasicDBObject doc = new BasicDBObject();
              doc.put("name.first", "First Name");
              doc.put("name.last", "Last Name");
              coll.insert(doc);
      
          }
      }
      

        Activity

        Hide
        Scott Hernandez
        added a comment -

        This patch should check for "$" as well.

        Show
        Scott Hernandez
        added a comment - This patch should check for "$" as well.
        Hide
        Antoine Girbal
        added a comment - - edited

        looking into this, it seems that:

        • for insert/save, the object's keys are checked for "." (anywhere) and "$" (1st char)
        • for all other operations (like update) no check is done.

        For example with update I can get:
        { "_id" :

        { "$oid" : "4d645eb2b8fbd47f326e46ad"}

        , "a.b" : 31}

        My understanding is that driver should apply check on update object, as long as first key does not start with "$".

        Show
        Antoine Girbal
        added a comment - - edited looking into this, it seems that: for insert/save, the object's keys are checked for "." (anywhere) and "$" (1st char) for all other operations (like update) no check is done. For example with update I can get: { "_id" : { "$oid" : "4d645eb2b8fbd47f326e46ad"} , "a.b" : 31} My understanding is that driver should apply check on update object, as long as first key does not start with "$".
        Hide
        Scott Hernandez
        added a comment -

        Yep, sounds correct.

        Show
        Scott Hernandez
        added a comment - Yep, sounds correct.
        Hide
        auto
        added a comment -

        Author:

        {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

        Message: JAVA-151: Dot allowed in key names
        https://github.com/mongodb/mongo-java-driver/commit/314a46393748b616ed55b5738cd61d1b72d4ec2f

        Show
        auto
        added a comment - Author: {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'} Message: JAVA-151 : Dot allowed in key names https://github.com/mongodb/mongo-java-driver/commit/314a46393748b616ed55b5738cd61d1b72d4ec2f
        Hide
        Antoine Girbal
        added a comment -

        fixed and added test

        Show
        Antoine Girbal
        added a comment - fixed and added test

          People

          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              3 years, 9 weeks ago
              Date of 1st Reply: