2011-04-20 14 views
11

मैं केवल 1 विशेष मॉडल के साथ इस मुद्दे आ रही है जब मैं आईडीmongoid वी.एस. जहां

>> Cart.where(:_id => '4dae5902e1607c232c000009').first 
=> #<Cart _id: 4dae5902e1607c232c000009, _id: BSON::ObjectId('4dae5902e1607c232c000009'), _type: nil> 
>> Cart.find('4dae5902e1607c232c000009') 
Mongoid::Errors::DocumentNotFound: Document not found for class Cart with id(s) 4dae5902e1607c232c000009. 

से तलाश कर रहा हूँ अजीब बात यह है कि अन्य मॉडलों के साथ, मैं ठीक लगता है का उपयोग कर सकते है। कोई विचार?

ढेर के बाकी है ...

from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criterion/inclusion.rb:192:in `execute_or_raise' 
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criterion/inclusion.rb:190:in `tap' 
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criterion/inclusion.rb:190:in `execute_or_raise' 
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criterion/inclusion.rb:106:in `find' 
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/finders.rb:67:in `find' 
from (irb):37 

उत्तर

3

आम तौर पर इस मुद्दे को दूसरी तरह के आसपास है। जहां असफल हो रहा है और काम मिल रहा है।

यही वजह है कि क्वेरी से पहले बीएसओएन :: ऑब्जेक्टआईडी में आईडी कास्टिंग नहीं किया जा रहा है।

आमतौर पर आप इस

Cart.where(:_id => BSON::ObjectId('4dae5902e1607c232c000009')).first 

इस ओर जाता है मुझे विश्वास है कि अपने आईडी और तारों के रूप में जमा हो जाती है नहीं BSON करना होगा: ObjectId और समझा जाएगा क्यों खोजने में विफल रहता है (यह एक BSON लिए खोज रहा है :: ऑब्जेक्टआईड एक स्ट्रिंग नहीं है)

यह भी समझा सकता है कि यह केवल एक मॉडल क्यों है क्योंकि यह पूरी तरह निर्भर करता है कि वस्तुओं को कैसे संग्रहीत किया जाता है।

आशा है कि

में मदद करता है