Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3573

BSON library assumes $ref values containing a period are a full namespace

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: BSON

      What problem are you facing?

      When a string containing a single period (e.g. "a.b") is provided as the $ref value when creating a DBRef, the part of the string before the period is interpreted as $db, and the part after as $ref.

      If a string with multiple periods is provided (e.g. "a.b.c") no splitting occurs and the entire string is treated as $ref.

      Essentially, it seems that there is no way to create a DBRef where $ref references a collection with a single period in the name. Also note that, even if $db is specified along with a $ref containing a single period, the provided value for $db is just ignored:

      test> DBRef("a.b", ObjectId(), "c")
      DBRef("b", ObjectId("6126ae033245354afbb8a17b"), "a")

      Investigating one other driver that models a DBRef, pymongo, they make no attempt to interpret $ref as a namespace and just leave it as is. The only way to set a value for $db is to explicitly provide one.

      What driver and relevant dependency versions are you using?

      js-bson 4.5.1. This behavior does not appear to exist in BSON v1 (which driver v3 uses): https://github.com/mongodb/js-bson/blob/1.0-branch/lib/bson/db_ref.js#L10

      Steps to reproduce?

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            kaitlin.mahar@mongodb.com Kaitlin Mahar
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: