【问题标题】:How to add getlocation in mongoose如何在猫鼬中添加getlocation
【发布时间】:2020-05-15 15:05:51
【问题描述】:

我需要在现有的 mongoose 模式中添加一个新的 location 字段,我已更新集合中的文档以添加新字段 updateMany({}, { $set: { "details.loc": { type: "Point", coordinates: [-0, 0] } } }) 并添加了该字段... 我还更新了架构以包含

...
loc: {
    type: { type: String }
  , coordinates: []
     },

带有strict:false 选项 但是当我尝试添加带有位置数据的新文档时......它没有反映

db.create( {"details.loc": { type: 'Point', coordinates: [property.lat, property.lang] }});

我该如何解决这个问题?

【问题讨论】:

    标签: mongodb mongoose


    【解决方案1】:

    这样做

    因为,您使用的参考符号仅适用于更新文档。对于创建,您必须像这样编写完整的对象

    db.create( {"details":{"loc": { type: 'Point', coordinates: [property.lat, property.lang] }}});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-20
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 2019-01-20
      • 2011-10-31
      • 1970-01-01
      相关资源
      最近更新 更多