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

Unable to determine if field is of type array when field name is all numeric characters

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

      BSON allows for a field name to be all numeric characters. For example:

      { "_id" : 102, "0" : [ "Junk", "Garbage", "ETC" ], "name" :

      { "first" : "John", "last" : "Backus" }

      , "birth" : ISODate("1924-12-03T05:00:00Z"), "death" : ISODate("2007-03-17T04:00:00Z"), "contribs" : [ "Fortran", "ALGOL", "Backus-Naur Form", "FP" ], "awards" : [

      { "award" : "W.W. McDowell Award", "year" : 1967, "by" : "IEEE Computer Society" }

      ,

      { "award" : "National Medal of Science", "year" : 1975, "by" : "National Science Foundation" }

      ,

      { "award" : "Turing Award", "year" : 1977, "by" : "ACM" }

      ,

      { "award" : "Draper Prize", "year" : 1993, "by" : "National Academy of Engineering" }

      ] }

      I am currently working on a system where I need to evaluate every field in a mongo document at every level of the document. One of the pieces of data I collect about each field is whether or not the field is an array.

      In my simple example above, If I want to determine that field "0" is an array, I execute the following:

      db.people.find({$where : "Array.isArray(this.0)"})

      This results in an error:
      error:

      { "$err" : "SyntaxError: Unexpected number", "code" : 16722 }

      I've scoured the internet trying to find an alternative way to get this information, but I've not been successful. Is there another way to determine whether a field is an array in scenario where the field name all numeric characters?

      Thanks

            Assignee:
            Unassigned Unassigned
            Reporter:
            bmiller1009 Brad Miller
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: