Rails Rails 使用 Mongoid 出现 Cant canonicalize query

loyalpartner · February 16, 2015 · Last by loyalpartner replied at February 16, 2015 · 2459 hits

rails 版本:4.2.0 mongid 版本:4.0.0

出错代码: @current_user ||= (User.find session[:user_id] if session[:user_id])

The operation: #<Moped::Protocol::Query @length=93 @request_id=9 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="mongoid_study_development.users" @skip=0 @limit=0 @selector={"_id"=>{"$oid"=>BSON::ObjectId('54ddcb9e6361700900000000')}} @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.

是 id 还是 oid?

#1 楼 @heylonj 我存到 session 里面的时候 session[:user_id] 还是 BSON::ObjectId('54ddcb9e6361700900000000'),可是页面加载完,session[:user_id] 就变成 {"$oid"=>"54ddcb9e6361700900000000"}

3 Floor has deleted
4 Floor has deleted
session[:user_id] = user.id.to_s
You need to Sign in before reply, if you don't have an account, please Sign up first.