0

在带有 Mongoid 2.4、BSON 1.5 的 Rails 3.1 上

我无法使用 Mongoid 的 Model.find 通过 :_id 找到模型

在哪里使用:

>> Athlete.where(:_id => BSON::ObjectId.from_string('4f2b22d70f67e90001001edd')).first
=> #<Athlete _id: 4f2b22d70f67e90001001edd, ...>

使用查找:

>> Athlete.find('4f2b22d70f67e90001001edd')
=> nil

知道我做错了什么吗?

4

1 回答 1

0

您需要手动构建您的 mongoid 索引:

rake db:mongoid:create_indexes
于 2012-04-19T19:10:21.910 回答