Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14330

Applying Array.isArray to a field containing a hyphen

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.1
    • Component/s: Querying
    • Labels:
      None

      I have a program which inspects every field in a document to see if it an array.

      This works fine for:

      db.bios.find({$where: "Array.isArray(this.awards)"})
      <Returns values>

      But not for

      db.messages.find({$where: "Array.isArray(this.X-cc)"})
      error:

      { "$err" : "ReferenceError: cc is not defined", "code" : 16722 }

      If I single-quote the parameter value in isArray it breaks the working use case:

      db.bios.find({$where: "Array.isArray('this.awards')"})
      <No rows return>

      and seems to fix the broken use case:
      db.messages.find({$where: "Array.isArray(this.X-cc)"})
      <No rows returned instead of an error>

      What I'm looking for is a generic solution that can be used in both scenarios.

      Thanks,

      Brad

            Assignee:
            kamran.khan Kamran K.
            Reporter:
            bmiller1009 Brad Miller
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: