Assuming the following document structure, how is it possible to use a variable to define the indicated key? Values could be observational, surreal, physical, other.
If an object needs to be used to create the update, please show how. If it would be better to restructure the document then suggestions are welcome.
Comedians.update(
{ "id":row[0]},
{ 'id':row[0],
'surname':row[1],
'firstName':row[2],
'observational':{ //<--key generated dynamically (observational/ surreal/ physical)
'routines':{
'year1':{
'club1':row[6],
'club2':row[8],
'club3':row[10]
},
'year2':{
'club1':row[14],
'club2':row[16],
'club3':row[18]
},
'year3':{
'club1':row[20],
'club2':row[22],
'club3':row[24]
}
},
'jokes':{
'year1':{
'club1':row[7],
'club2':row[9],
'club3':row[11]
},
'year2':{
'club1':row[13],
'club2':row[15],
'club3':row[17]
},
'year3':{
'club1':row[19],
'club2':row[21],
'club3':row[23]
}
},
}
},
{upsert: true},
function(error,result){
if ( error ) console.log ( error );
if ( result ) console.log ( result );
});
Other answers on SO do not utilize embedded documents and this appears to be an issue here.