mongodb - How to access embedded documents in MongoTemplate when the key is an empty string? -


{         "_id" : objectid("550add7ee0b4b54a3e7ad53c"),         "day" : "14-03-2015",         "node" : "2g",         "nodename" : "blr_sgsn",         "" : {                 "a" : 905.84,                 "b" : 261.34,                 "c" : 2103.94,                 "d" : 39.67         } } 

i have data in mongo. how values of a,b,c,d. ??

you cannot query on sub-document fields cannot selected.

this can result of programming error doing ( , trying compute key name in process ):

db.collection.insert({     "": {         "a": 1,         "b": 2,         "c": 3     }     }) 

so cannot sub-elements standard query ways like:

db.collection.find({ ".a": 905.84 }) 

you can fix updating documents in collection affected in way giving them proper key name. of course iterative process. not sure how fix other javascript shell due naming problem but:

db.collection.find({ "": { "$exists": true } }).foreach(function(doc) {      if ( doc.hasownproperty("") ) {          doc.newprop = doc[""];         delete doc[""];         db.collection.update({ "_id": doc._id }, doc );     } }) 

then @ least can access things new "newprop" key ( or whatever call ):

db.collection.find({ "newprop.a": 905.84 }) 

and same sort of thing work in other drivers.

my advice here "go , fix this" , find out code caused key name blank in first place.

there should bug report submitted mongodb core project none of dirvers handle well. thought use $rename here, can't.

so blank "" keys problem needs fixed.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -