Hi guys i am new to mongodb i am trying to write a query to get a single field value from db:
{
"_id" : "vK4PvdNBfBbdv92PH",
"ownerId" : "J8MpsWChPQdET6jwQ",
"createdAt" : ISODate("2018-07-04T07:25:28.406Z"),
"spots" : [
{
"name" : "spot1",
"construction" : false,
"constructingBuildingName" : "",
"buildingName" : "factory",
"level" : 1,
"startTime" : 0,
"finishTime" : 0
},
{
"name" : "spot2",
"construction" : true,
"constructingBuildingName" : "Farm",
"buildingName" : "",
"level" : 0,
"startTime" : 1530863511,
"finishTime" : 1530864011
},
{
"name" : "spot3",
"construction" : false,
"constructingBuildingName" : "",
"buildingName" : "",
"level" : 0,
"startTime" : 0,
"finishTime" : 0
}
]
}
In this case I am trying to get under spot2 “constructingBuildingName” s “Farm” value.
What i wrote is :
var constructingBuildingName = Towns.find({ownerId:userid,spots:{$elemMatch:{name:spot}}});
spot is = “spot2”
What should be the rest ?