Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Mongodb错误代码10068或17287,带有rails 4.1和Desive_Ruby On Rails_Mongodb_Devise_Mongoid_Ruby On Rails 4.1 - Fatal编程技术网

Ruby on rails Mongodb错误代码10068或17287,带有rails 4.1和Desive

Ruby on rails Mongodb错误代码10068或17287,带有rails 4.1和Desive,ruby-on-rails,mongodb,devise,mongoid,ruby-on-rails-4.1,Ruby On Rails,Mongodb,Devise,Mongoid,Ruby On Rails 4.1,我尝试将mongoid与Rails 4.1.0应用程序一起使用,但在moongodb 2.6.0上出现错误17287(与早期版本的mongodb上的10068相同)。 以下是错误消息: The operation: #<Moped::Protocol::Query @length=127 @request_id=5 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="educandose_development.use

我尝试将mongoid与Rails 4.1.0应用程序一起使用,但在moongodb 2.6.0上出现错误17287(与早期版本的mongodb上的10068相同)。 以下是错误消息:

The operation: #<Moped::Protocol::Query @length=127 @request_id=5 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="educandose_development.users" @skip=0 @limit=-1 @selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534d6f4f6372618443000000')}}, "$orderby"=>{:_id=>1}} @fields=nil> failed with error 17287: "Can't canonicalize query: BadValue unknown operator: $oid" See https://github.com/mongodb/mongo/blob/master/docs/errors.md for details about this error.
操作:{{{u id=>{“$oid”=>BSON::ObjectId('534d6f4f6372618443000000')},“$orderby”=>{:\u id=>1}}}@fields=nil>失败,错误17287:“无法规范化查询:BadValue未知运算符:$oid”请参阅https://github.com/mongodb/mongo/blob/master/docs/errors.md 有关此错误的详细信息。

你知道哪里有问题吗?

在寻找了一段时间后,我意识到rails 4.1上新的json cookies序列化程序打破了Desive资源上的MOPE查询

要解决此问题,请删除cookies_serializer.rb初始值设定项上的以下行

Rails.application.config.action_dispatch.cookies_serializer = :json
您可能希望返回旧的sessions_store.rb文件,其内容类似于:

YourApp::Application.config.session_store :cookie_store, key: '_yourapp_session'
或者尝试设计的主要分支

请看这里:
这里:

在修复moped/session/json格式之前,我暂时使用:

# app/models/concerns/zero_oid_fix.rb
module ZeroOidFix
  extend ActiveSupport::Concern

  module ClassMethods
    def serialize_from_session(key, salt)
      record = to_adapter.get((key[0]["$oid"] rescue nil))
      record if record && record.authenticatable_salt == salt
    end
  end
end
在设计模型中:

class User

  devise :database_authenticatable, ...

  # NOTE: Has to be after devise
  include ZeroOidFix

  ...
end
希望这个答案很快就会过时

  • 注释掉cookies_serializer.rb中的以下行

    Rails.application.config.action_dispatch.cookies_serializer=:json

  • 删除cookies

  • 重新启动服务器


  • 在“rails 4.1.4,Desive 3.2.4,mongoid 4.0.0”上为我工作过

    此修复对我工作过,谢谢。然而,我不太明白为什么会发生这个错误,以及这个修复是如何工作的。您能解释一下发生了什么吗?@Kira BSON ObjectId序列化将其存储为普通十六进制字符串更改为object
    {“$oid”:“hextstring”}
    ,因此它更符合MongoDB的扩展JSON格式约定(在一个库中更改,但在另一个库中未更改).这个补丁对mongoid 4.0.0和rails 4.1.4来说都很有吸引力。对我来说都很有效!谢谢。如果选中
    记住我
    复选框,则此选项将中断。下次打开浏览器时会抛出错误。如果尚未清除cookie,则会导致:ActionView::Template::error(需要不兼容的封送处理文件格式(无法读取)格式版本4.8;给出123.34)。清理你的饼干,这些就消失了。