0
我想寫一個貓鼬查詢獲取一堆場地,並做一個谷歌查詢來獲得這些場地的距離,並在返回它們之前將該距離添加到每個場地對象。 繼承人的相關代碼(CoffeeScript的):如何添加到一個mongo對象並返回它
Venue.find
.then (dbResponse) ->
venues = dbResponse
googleParam = ''
console.log venues
venues.forEach (venue) ->
googleParam += venue.streetAddress + '+' + venue.city + '+' + venue.state + '|'
request
url: "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Times+Sq+New+York+NY&destinations=" + googleParam + "&key=" + process.env.GOOGLE_MAPS_API_KEY
json: true
.then (response) ->
venues = _.map venues, (venue, index) ->
console.log index
venue.distance = response.rows[0].elements[index].distance.text
console.log venue.distance
venue
res.json venues
當我CONSOLE.LOG venue.distance我得到正確的值,但仍然反應沒有距離,就在老場地對象回來。