我有一个通过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>'
This thread在mongomapper组建议我在
ensure_index
集合上运行create_index
(或files.chunk
)。但是,我不知道如何与Mongomapper做这件事。有没有办法防止这种情况?
最佳答案
我也有同样的问题,正如作者所说,那句话:
db.fs.chunks.ensureIndex({files_id: 1, n: 1})
内部控制台有帮助。
完整的算法是:
打开终端,键入
mongo
。按回车键。键入
mongo
。按回车键。键入
use <your database name>
。按回车键。关于mongodb - Mongo::OperationFailure,数据库命令'filemd5'失败:(错误:'异常(exception):请求最佳猜测计划,但需要扫描和订购),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7961653/