javascript - MongoDb map-reduce exception -


i have following prototype:

{     "_id" : "nwva",     "cat" : {         "_id" : objectid("4ffee943e4b08a66fd8e84a1"),         "slug" : "fun"     },     "imp" : false,     "int" : {         "comm" : 0,         "fblk" : 1,         "fbsh" : 0     } } 

and following map reduce function:

var mapfunction1 = function() {     if (!this.int || (typeof this.int != 'object')) {         this.int = {};     }     var lk = this.int.lk;     var dlk = this.int.dlk;     .....     ..... }; 

when have prototype without field "int", i've got error:

javascript execution failed: map reduce failed:{ "errmsg" : "exception: javascript execution failed: typeerror: cannot read property 'lk' of undefined near '= this.int.lk; \t\tvar dlk = this.int.dlk' (line 5)", "code" : 16722, "ok" : 0 }

i have tried everything, assigned "this.int = {};" , nothing.

i've tried unsuccessfully several ways assign empty object when this.int undefined in order avoid exception.

is variable read-only in map function scope?

how can resolve this?

additional info

here have simple test:

db.contenido.insert( { "_id": "flor" }); db.contenido.find({ "_id": "flor" } ); { "_id" : "flor" }  db.contenido.mapreduce(function() { var lk = this.int.lk;}, function() {}, { query :  { "_id" : "flor" }, out : { inline : 1 },verbose: 1 });  tue jul 23 17:39:53.114 javascript execution failed: map reduce failed:{     "errmsg" : "exception: javascript execution failed: typeerror: cannot read property 'lk' of undefined near '= this.int.lk; printjsononeline( this.int' ",     "code" : 16722,     "ok" : 0 } @ src/mongo/shell/collection.js:l970  db.contenido.mapreduce(function() { if (!this.int || (typeof this.int != 'object')) {this.int = {};} var lk = this.int.lk;}, function() {}, { query :  { "_id" : "flor" }, out : { inline : 1 },verbose: 1 });  tue jul 23 17:41:04.035 javascript execution failed: map reduce failed:{     "errmsg" : "exception: javascript execution failed: typeerror: cannot read property 'lk' of undefined near '= this.int.lk;}' ",     "code" : 16722,     "ok" : 0 } @ src/mongo/shell/collection.js:l970   db.contenido.mapreduce(function() { this.int = {}; var lk = this.int.lk;}, function() {}, { query :  { "_id" : "flor" }, out : { inline : 1 },verbose: 1 });   tue jul 23 17:41:21.926 javascript execution failed: map reduce failed:{     "errmsg" : "exception: javascript execution failed: typeerror: cannot read property 'lk' of undefined near '= this.int.lk;}' ",     "code" : 16722,     "ok" : 0 } @ src/mongo/shell/collection.js:l970 


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -