2017-04-17 26 views
0

我正在研究nodejs後端的地理位置搜索。而mongodb是數據庫。爲了做到這一點,我從前端獲得價值。我正在使用地圖getbound來獲取視口數據。以下是一些包含經度和緯度的變量。如何創建座標數組?

var topLeftLong = parseFloat(req.body.topLeftLong); 
    var topLeftLat = parseFloat(req.body.topLeftLat); 

    var topRightLong = parseFloat(req.body.topRightLong); 
    var topRightLat = parseFloat(req.body.topRightLat); 

    var bottomRightLong = parseFloat(req.body.bottomRightLong); 
    var bottomRightLat = parseFloat(req.body.bottomRightLat); 

    var bottomLeftLong = parseFloat(req.body.bottomLeftLong); 
    var bottomLeftLat = parseFloat(req.body.bottomLeftLat); 

雖然我得到這些數據,我想把經度和緯度放在一個數組中。但是每當我嘗試在數組中推送數據時,我都會得到下面的錯誤。

This is error from mongodb (may be)

回答

0

好像錯誤的數據類型是罪魁禍首。在你的代碼中,如果你使用了cast,例如(int)string-var,那麼它可能是由於這個錯誤。數據類型很重要。不匹配的數據類型會導致錯誤。