MongoDB: Cannot refer to field with a space -


i have mongodb collection ph_location, , 1 document in it:

> db.ph_location.findone({}) {     "_id" : objectid("579662fec773d83e625f71e8"),     "postal code" : 2800,     "town" : "bangued",     "province" : "abra",     "metro" : "" } 

i having trouble referring field "postal code". find , update operations use field cannot locate it. instance:

> db.ph_location.findone({},{"postal code":1}) { "_id" : objectid("579662fec773d83e625f71e8") } 

and

> db.ph_location.updatemany({}, {$rename:{"postal code":"zip_code"}}) { "acknowledged" : true, "matchedcount" : 2271, "modifiedcount" : 0 } 

any ideas problem be?

i'll bet non-breaking space , not regular space.

try this:

db.ph_location.find({"postal\u00a0code" : 2800}) 

you can debug characters in keys using this:

function codepoints(str) {     var result = "";     (var = 0, len = str.length; < len; i++) {         result += "'" + str[i] + "':" + str.charcodeat(i) + ", ";     }     return result; } function walk(obj) {   (prop in obj) {     if (obj.hasownproperty(prop) && isnan(prop)) {       print(prop + " " + codepoints(prop));       walk(obj[prop]);     }   } } var cursor = db. ph_location.find() while ( cursor.hasnext() ) {     obj = cursor.next();     walk(obj); } 

look spaces ' ' in output. see:

' ':32 

if space, or

' ':160 

if non- breaking space, or other code if other char.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -