error saving file with joint

84 views
Skip to first unread message

Fabrizio Regini

unread,
Jan 11, 2011, 9:46:20 AM1/11/11
to mongo...@googlegroups.com
Hi,
I'm getting this error wile saving a file on a joint powered model:

Mongo::OperationFailure: Database command 'filemd5' failed: {"errmsg"=>"exception: best guess plan requested, but scan and order required: query: { files_id: ObjectId('4d2c6aed069cec2473000002') } order: { files_id: 1, n: 1 } choices: { $natural: 1 } ", "code"=>13284, "ok"=>0.0}

I'm using:

MM 0.8.6
Joint 0.5.2
mongo 1.1.5

Mongo Database is at version 1.6.3

Any clue?


Brian Hempel

unread,
Jan 11, 2011, 9:51:03 AM1/11/11
to mongo...@googlegroups.com
I think mongodb can be started with an option to not allow table scan operations, which forces queries to fail if they can't use indexes. So maybe your database was started with that option. If so, you can add an appropriate index.

Brian Hempel

> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en

Kyle Banker

unread,
Jan 11, 2011, 11:51:40 AM1/11/11
to MongoMapper
If the filemd5 command fails, this usually caused by having the wrong
indexes in place. Which indexes are defined on your chunks collection?

Fabrizio Regini

unread,
Jan 11, 2011, 11:53:39 AM1/11/11
to mongo...@googlegroups.com
There's no such option in my config file. This is it's content:

dbpath = /data/db
bind_ip = 127.0.0.1
logpath = /opt/local/var/log/mongodb/mongodb.log
logappend = 1
verbose = 1

Fabrizio Regini

unread,
Jan 11, 2011, 12:04:10 PM1/11/11
to mongo...@googlegroups.com
Hi Kyle,
I get this error running my test suite, It used to work with a previous gems config. I run a bundle update and find the tests to fail with that error message.
One strange think I'm noticing:

These are the indexes in my development database:

> db.fs.chunks.getIndexes()
[
{
"name" : "_id_",
"ns" : "acme_development.fs.chunks",
"key" : {
"_id" : 1
}
},
{
"unique" : true,
"ns" : "acme_development.fs.chunks",
"name" : "files_id_1_n_1",
"key" : {
"files_id" : 1,
"n" : 1
}
}
]

While these are the indexes in my test database:

> db.fs.chunks.getIndexes()
[
{
"name" : "_id_",
"ns" : "acme_test.fs.chunks",
"key" : {
"_id" : 1
}
}
]

Now I'm trying to understand why this difference and if this may be the cause. I actually did not try that feature in the development live app.

Fabrizio Regini

unread,
Jan 11, 2011, 12:55:49 PM1/11/11
to mongo...@googlegroups.com
I really can't figure out where my indexes on fs.chunks and fs.files are coming from.
I can't find any of them in the joint gem or in mongomapper.
In mongomapper I can't manage indexes directly on those collections, so I'm thinking on putting them into an initializer. What's the suggested approach in this case?

On 11/gen/2011, at 17.51, Kyle Banker wrote:

Kyle Banker

unread,
Jan 12, 2011, 12:22:42 PM1/12/11
to MongoMapper
That's definitely the problem. You need the index on files_id and n in
production. This is usually created when you instantiate Grid. Not
sure why that index creation command wouldn't have been fired in
production, but you can certainly put it in an initializer. Just
connect to the database, instantiate the files.chunks collection and
then run:

@chunks.create_index([['files_id', Mongo::ASCENDING], ['n',
Mongo::ASCENDING]], :unique => true)

Fabrizio Regini

unread,
Jan 12, 2011, 4:41:19 PM1/12/11
to mongo...@googlegroups.com
Hi Kyle,
thanks, I did something similar in a initializer with ensure_index,
I guess it's the same as create_index in this case. You say when I
instantiate the Grid, but I'm not actually doing anything with the
ruby driver itself, it's all done through MM and Joint, so I guess
we should point the attention to those libs. Anyone with a similar
setup is having the same issue?

Why do you mention the produciton environment? Is there something
to be triggered depending on the Rails.env?

Kyle Banker

unread,
Jan 13, 2011, 11:51:37 AM1/13/11
to MongoMapper
I meant production database.
Reply all
Reply to author
Forward
0 new messages