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:
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