Mongo :: OperationFailure,数据库命令'filemd5'失败:(错误:'例外:请求最佳猜测计划,但需要扫描和订购)

时间:2011-11-01 01:37:47

标签: mongodb mongomapper gridfs

我有一个应用程序,通过Padrino中的MongoMapper / Joint将文件上传到GridFS。一切都很好,然后突然间,我收到了错误:

Mongo::OperationFailure at /admin/wallpapers/create
Database command 'filemd5' failed: (errmsg: 'exception: best guess plan requested, but scan and order required: query: { files_id: ObjectId('4eaf4abf9972772c94000003') } order: { files_id: 1, n: 1 } choices: { $natural: 1 } '; code: '13284'; ok: '0.0').

堆栈跟踪:

Mongo::OperationFailure - Database command 'filemd5' failed: (errmsg: 'exception: best guess plan requested, but scan and order required: query: { files_id: ObjectId('4eaf4c719972772c9400000b') } order: { files_id: 1, n: 1 } choices: { $natural: 1 } '; code: '13284'; ok: '0.0').:
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo-1.4.1/lib/mongo/db.rb:520:in `command'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo-1.4.1/lib/mongo/gridfs/grid_io.rb:463:in `get_md5'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo-1.4.1/lib/mongo/gridfs/grid_io.rb:453:in `to_mongo_object'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo-1.4.1/lib/mongo/gridfs/grid_io.rb:238:in `close'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo-1.4.1/lib/mongo/gridfs/grid.rb:73:in `put'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/joint-0.6.0/lib/joint/instance_methods.rb:22:in `block in save_attachments'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/joint-0.6.0/lib/joint/instance_methods.rb:18:in `each_pair'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/joint-0.6.0/lib/joint/instance_methods.rb:18:in `save_attachments'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/activesupport-3.0.10/lib/active_support/callbacks.rb:416:in `_run_save_callbacks'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/activesupport-3.0.10/lib/active_support/callbacks.rb:94:in `run_callbacks'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/embedded_callbacks.rb:28:in `run_callbacks'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/callbacks.rb:14:in `create_or_update'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:143:in `save'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/dirty.rb:20:in `block in save'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/dirty.rb:42:in `clear_changes'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/dirty.rb:20:in `save'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/validations.rb:23:in `save'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:30:in `block in create'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:113:in `block in initialize_each'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:111:in `each'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:111:in `initialize_each'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:30:in `create'
 /var/www/fhsclock/admin/controllers/wallpapers.rb:13:in `block (2 levels) in <top (required)>'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:486:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:486:in `block in route'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:736:in `instance_eval'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:736:in `route_eval'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:49:in `block (2 levels) in process_destination_path'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:49:in `catch'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:49:in `block in process_destination_path'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:22:in `instance_eval'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:22:in `process_destination_path'
 (eval):16:in `block (2 levels) in inject_root_methods'
 (eval):6:in `catch'
 (eval):6:in `block in inject_root_methods'
 (eval):313:in `block in inject_root_methods'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/http_router-0.8.11/lib/http_router/node/root.rb:68:in `[]'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/http_router-0.8.11/lib/http_router.rb:110:in `block in call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/http_router-0.8.11/lib/http_router.rb:110:in `catch'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/http_router-0.8.11/lib/http_router.rb:110:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:796:in `route!'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:785:in `dispatch!'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:656:in `block in call!'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:820:in `block in invoke'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:820:in `catch'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:820:in `invoke'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:656:in `call!'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:641:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/rack-flash-0.1.2/lib/rack/flash.rb:147:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/reloader.rb:243:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/logger.rb:300:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/showexceptions.rb:21:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/rack-1.3.5/lib/rack/session/abstract/id.rb:195:in `context'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/rack-1.3.5/lib/rack/session/abstract/id.rb:190:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/rack-1.3.5/lib/rack/head.rb:9:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/showexceptions.rb:21:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/rack-1.3.5/lib/rack/methodoverride.rb:24:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:1292:in `block in call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:1323:in `synchronize'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:1292:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/router.rb:71:in `block in call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/router.rb:64:in `each'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/router.rb:64:in `call'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:84:in `block in pre_process'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:82:in `catch'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:82:in `pre_process'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:57:in `process'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:42:in `receive_data'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thin-1.2.11/lib/thin/backends/base.rb:61:in `start'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thin-1.2.11/lib/thin/server.rb:159:in `start'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/rack-1.3.5/lib/rack/handler/thin.rb:13:in `run'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/rack-1.3.5/lib/rack/server.rb:265:in `start'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/server.rb:44:in `start'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/server.rb:34:in `start'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/server.rb:13:in `run!'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/cli/adapter.rb:7:in `start'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/cli/base.rb:24:in `start'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thor-0.14.6/lib/thor.rb:263:in `dispatch'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/gems/padrino-core-0.10.0/bin/padrino:9:in `<top (required)>'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/bin/padrino:19:in `load'
 /home/ethan/.rvm/gems/ruby-1.9.2-p290@fhsclock/bin/padrino:19:in `<main>'
MongoMapper小组的

This thread建议我在ensure_index集合上运行create_index(或files.chunk)。但是,我不知道如何使用MongoMapper。

有没有办法阻止这种情况?

4 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,正如作者所建议的那样:

db.fs.chunks.ensureIndex({files_id: 1, n: 1})

内部mongo控制台帮助。

完整算法是:

  1. 打开终端,输入mongo。按enter键。
  2. 输入use <your database name>。按enter键。
  3. 输入db.fs.chunks.ensureIndex({files_id: 1, n: 1})。按enter键。

答案 1 :(得分:0)

YourClassName.ensureIndex(:files_id)

答案 2 :(得分:0)

this thread中的最后一个答案会帮助你吗?

答案 3 :(得分:0)

从数据库配置中删除:slave_ok => true后,一切正常。根据MongoDB文档,它甚至不应该使用奴隶。但是,无论如何......