【问题标题】:How would I access the values of the coordinates through a NodeJS MongoDB query?如何通过 NodeJS MongoDB 查询访问坐标值?
【发布时间】:2021-07-21 23:45:51
【问题描述】:
    "_id" : ObjectId("607ce141dfc52641ea652fb2"), 
    "Timestamp" : ISODate("2020-11-18T02:38:22.000+0000"), 
    "Class" : "Class A", 
    "MMSI" : 219022256, 
    "MsgType" : "position_report", 
    "Position" : {
        "type" : "Point", 
        "coordinates" : [
            54.572058, 
            11.928778
        ]
    }, 
    "Status" : "Under way using engine", 
    "RoT" : 0.0, 
    "SoG" : 0.0, 
    "CoG" : 264.6, 
    "Heading" : 207
}

这是我的查询: const ship = await ais 。总计的( [{ $match: { MMSI: 219022256 } }, { $sort: { Timestamp: -1 } }], { 允许磁盘使用:真, } ) .project({ _id: 0 }) .limit(1) .toArray();

【问题讨论】:

    标签: javascript node.js arrays mongodb


    【解决方案1】:

    考虑到返回值,您可以使用一个对象数组(JSON 对象),因此您可以像这样使用每个对象的信息:

    for(let i = 0; i < Ships.length; i++){
       console.log(Ships[i]["Position"]["Coordinates"]);
       let myCoordinates = Ships[i]["Position"]["Coordinates"];
       let lat = myCoordinates[0];
       let lon = myCoordinates[1];
       // Use the coordinates
    }
    

    干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 2019-11-09
      • 2013-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多