【问题标题】:Migrate geo data from MongoMapper to Mongoid将地理数据从 MongoMapper 迁移到 Mongoid
【发布时间】:2019-05-16 14:52:55
【问题描述】:

我有以这种方式在 MongoMapper 中保存数据的模型

class WellIndex::Core
 include MongoMapper::Document

 key :well_name 
 key :surface_loc, Hash
 ensure_index [[:surface_loc, '2dsphere']]
end

数据以这种方式存储

well.surface_loc # {:type => "Point", :coordinates => [-90, 10]}

我在 Mongoid 中看到您将地理数据存储到数组中。这个类将转换为

class WellIndex::Core
 include Mongoid::Document

 field :well_name, type: String
 field :surface_loc, Array
 index({:surface_loc => '2dsphere'})
end

这样我必须将所有数据迁移到一个新字段,因为数据是 Hash,有没有办法我仍然可以在 Mongoid 中使用相同的 Hash 数据强>?

【问题讨论】:

    标签: mongodb mongoid


    【解决方案1】:

    我发现我可以使用与上一篇文章中相同的数据保留相同的模型,但可以避免运行测试时出错。

    Mongo::Error::OperationFailure:
           error processing query: ns=worker_test.well_indexesTree: $and
               meas_depth $gt 4000
               GEONEAR  field=surface_loc maxdist=25 isNearSphere=0
    

    应该创建索引,如果您使用 rspec 则可以

    before(:each) { WellIndex::Core.create_indexes }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-29
      • 2012-01-24
      • 2010-12-18
      • 2012-04-11
      • 2015-11-11
      • 1970-01-01
      • 2023-03-05
      • 2017-08-15
      相关资源
      最近更新 更多