I have a Rails 3.1 app, running on Ruby 1.9.2, Mongo 2.0.2, using Mongoid as a ODM, however, this should be bypassing most of Mongoid and just using the MongoDB Ruby Driver. I am running a MapReduce query a few times on one page load. This will query will run acceptably for a while in development, say like half a day, then fail with a
(assertion: 'value has to be set';
assertionCode: '10210';
errmsg: 'db assertion failure';
ok: '0.0')
On a refresh of the page, everything continues to work wonderfully for some time. The log from execution (with some trimmed out)…
(R) MONGODB development['$cmd'].find({"mapreduce"=>"values", "map"=><BSON::Code:70098680478720 @data="function() {
var value = { a: 0, b: 0 };
var count = { a: 0, b: 0 };
var min = { a: 100, b: 100 };
var max = { a: -100, b: -100 };
if (this.c == "a" || this.c == "b") {
value[this.c] = parseInt(this.value);
count[this.c]++;
min[this.c] = parseInt(this.value);
max[this.c] = parseInt(this.value);
emit(this.item_id,
{
count: count,
values: value,
min: min,
max: max,
avg: { a: null, b: null }
}
);
}
}" @scope="{}">, "reduce"=><BSON::Code:70098680478680 @data="function(key, data) {
var newDatum = data.pop();
data.forEach(function(item) {
newDatum.values.a += item.values.a;
newDatum.count.a += item.count.a;
if (item.min.a < newDatum.min.a)
newDatum.min.a = item.min.a;
if (item.max.a > newDatum.max.a)
newDatum.max.a = item.max.a;
// same for b
});
newDatum.avg.a = newDatum.values.actual / newDatum.count.a;
newDatum.avg.b = newDatum.values.ideal / newDatum.count.b;
return newDatum;
}" @scope="{}">, :out=>{:inline=>1}, :query=>{:about_id=>BSON::ObjectId('4f1d84de69c238941d000012'), :by_id=>{"$ne"=>BSON::ObjectId('4f1d84de69c238941d000012')}, :comp_id=>{"$in"=>[BSON::ObjectId('4f1d84de69c238941d000016'), BSON::ObjectId('4f1d84de69c238941d000019')]}}}).limit(-1)
Now the query part for one that fails in the same request… (but again, will significantly more often than not succeed)
}" @scope="{}">, :out=>{:inline=>1}, :query=>{:about_id=>BSON::ObjectId('4f1d84de69c238941d000012'), :by_id=>BSON::ObjectId('4f1d84de69c238941d000012'), :comp_id=>BSON::ObjectId('4f1d84de69c238941d000019')}}).limit(-1)
Completed 500 Internal Server Error in 516ms
Mongo::OperationFailure (Database command 'mapreduce' failed: (assertion: 'value has to be set'; assertionCode: '10210'; errmsg: 'db assertion failure'; ok: '0.0').):
If it’s of any value, this is happening on Mac OS X Lion with Mongo installed via homebrew.
$ mongod --version
db version v2.0.2, pdfile version 4.5
Wed Feb 8 16:33:11 git version: 514b122d308928517f5841888ceaa4246a7f18e3
And what I can see in the log file during this event. The one line about mr failed seems to match to the event.
Wed Feb 8 15:08:36 [clientcursormon] mem (MB) res:15 virt:2630 mapped:80
Wed Feb 8 15:11:37 [clientcursormon] mem (MB) res:17 virt:2630 mapped:80
Wed Feb 8 15:16:37 [clientcursormon] mem (MB) res:17 virt:2630 mapped:80
Wed Feb 8 15:21:37 [clientcursormon] mem (MB) res:17 virt:2630 mapped:80
Wed Feb 8 15:26:37 [clientcursormon] mem (MB) res:17 virt:2630 mapped:80
Wed Feb 8 15:31:37 [clientcursormon] mem (MB) res:17 virt:2630 mapped:80
Wed Feb 8 15:32:55 [conn3] mr failed, removing collection :: caused
by :: 10210 value has to be set
Wed Feb 8 15:36:37 [clientcursormon] mem (MB) res:18 virt:2630 mapped:80
Wed Feb 8 15:39:26 [initandlisten] connection accepted from 127.0.0.1:57001 #4
So my question is, what can I do to help track this down? I am not noticing any additional issues with our use of Mongo. I’m not sure how to dig into this and figure out what’s going on.
So it appears the issue was JavaScript stored in the db itself.
db.system.js.find()listed a an entry without avalue. Per a post on the mongodb mailing list, removing that js seemed to correct the error. Hopefully if someone else runs into this, they’ll learn to checksystem.js.