gpt4 book ai didi

mongodb - MongoMapper 接近 maxDistance - Mongo::OperationFailure:地理值必须是数字:

转载 作者:可可西里 更新时间:2023-11-01 09:07:25 40 4
gpt4 key购买 nike

我正在尝试在 MongoMapper 支持的模型中封装一个具有 maxDistance 的近查询。

我一定是在我的查询语法中做了一些愚蠢的事情。

模型

class Site
include MongoMapper::Document

key :id, Integer
key :name, String
key :location, Array
ensure_index [[:location, '2d']]


def self.nearest(center_point, range)
where(:location => {'$near' => center_point, '$maxDistance' => range}).all
end

end

试图让所有东西都在一个点的 200 英里范围内......

Site.nearest([-122.0,44.0],200)

> Mongo::OperationFailure: geo values have to be numbers: {
> $maxDistance: 200, $near: [ -122.0, 44.0 ] } from
> /Library/Ruby/Gems/1.8/gems/mongo-1.6.1/lib/mongo/cursor.rb:144:in
> `next' from
> /Library/Ruby/Gems/1.8/gems/mongo-1.6.1/lib/mongo/cursor.rb:290:in
> `each' from
> /Library/Ruby/Gems/1.8/gems/mongo-1.6.1/lib/mongo/cursor.rb:308:in
> `to_a' from
> /Library/Ruby/Gems/1.8/gems/mongo-1.6.1/lib/mongo/cursor.rb:308:in
> `to_a' from
> /Library/Ruby/Gems/1.8/gems/plucky-0.4.4/lib/plucky/query.rb:74:in
> `all' from /Users/nick/Code/web/map/app/models/site.rb:40:in
> `nearest' from (irb):

最佳答案

您可能遇到了 this bug这需要 $near$maxDistance$maxDistance 一起排序。

无论如何,我发现这个问题是因为我在使用 PyMongo 时遇到了OperationFailure: database error: geo values have to be number,交换顺序修复了它。

关于mongodb - MongoMapper 接近 maxDistance - Mongo::OperationFailure:地理值必须是数字:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10020755/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com