Update Field with variable meteor mongo


#1

I have one collection called “Towns” with this document inside:

{
    "_id" : "vK4PvdNBfBbdv92PH",
    "ownerId" : "J8MpsWChPQdET6jwQ",
    "createdAt" : ISODate("2018-07-04T07:25:28.406Z"),
    "spot1" : {
        "construction" : false,
        "constructingBuildingName" : "",
        "buildingName" : "factory",
        "level" : 1,
        "startTime" : 0,
        "finishTime" : 0
    },
    "spot2" : {
        "construction" : false,
        "constructingBuildingName" : "",
        "buildingName" : "",
        "level" : 0,
        "startTime" : 0,
        "finishTime" : 0
    },
    "spot3" : {
        "construction" : false,
        "constructingBuildingName" : "",
        "buildingName" : "",
        "level" : 0,
        "startTime" : 0,
        "finishTime" : 0
    }
}

What i am trying to do is update in this case spot2s fields with variables.

spotName variable defines which spot field to update. update startTime,finishTime,constructingBuildingName,change construction to true

'buildNewBuilding':function(userid,buildingid,spotnumber){
var spotName  = "spot"+spotnumber.toString();
var data = Buildings.find({_id:buildingid}).fetch();
var constructingBuildingName = data[0].name;
var startTime = Math.floor(Date.now()/1000);
var finishTime = startTime+data[0].time;



Towns.update({ownerId:userid},{}) //??
//update startTime,finishTime,constructingBuildingName,change construction to true




  }

#2
Towns.update({ ownerId: userid }, { $set: { startTime, finishTime, constructingBuildingName, construction: true } })