[CSHARP-472] MapReduce fails with options SetQuery, SetSortOrder Created: 20/May/12  Updated: 20/Mar/14  Resolved: 22/May/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Roman Kuzmin Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File Program.cs    
Issue Links:
Related
related to SERVER-2269 Map/reduce with sorting fail Closed

 Description   

The attached Program.cs fails with the message:

Message=Command 'mapreduce' failed: db assertion failure (response: { "assertion" : "could not create cursor over test.test for query : { B:

{ $exists: true }

} sort :

{ B: 1 }

", "assertionCode" : 15876, "errmsg" : "db assertion failure", "ok" : 0.0 })

The code is based on the official test TestMapReduceInlineWithQuery. Perhaps
the problem can be seen just there if the line

var result = _collection.MapReduce(query, map, reduce);

is replaced with

var options = new MapReduceOptionsBuilder();
options.SetQuery(query);
options.SetOutput(MapReduceOutput.Inline);
options.SetSortOrder((new SortByBuilder()).Ascending("B"));
var result = _collection.MapReduce(map, reduce, options);

If I remove the line with SetSortOrder then the code works fine.

Sorry if I just do something wrong and this is a false alarm. I asked the
question at the forum but did not get the answer.



 Comments   
Comment by Robert Stam [ 11/Jun/12 ]

In what way does it not work?

The best thing you could do is create a sample of what you mean using the mongo shell and file a server ticket.

Comment by Nikolay Imshenitsky [ 11/Jun/12 ]

It removes the error but sorting still doesn't work.

Comment by Roman Kuzmin [ 22/May/12 ]

Yes, it works for me.

It is still an issue, MR or its documentation. But it has nothing to do with C# driver, of course.

Thank you for taking a look at this.

Comment by Robert Stam [ 22/May/12 ]

Looks like the server requires the existence of an appropriate index that it can use for the sort when using sort with map/reduce.

Try defining this index:

> db.test.createIndex(

{B:1}

)

and then it should work.

Comment by Roman Kuzmin [ 21/May/12 ]

I've tried this in the shell (after running my app, so that the test.test collection exists).

It fails with the same error message. It does not fail if I remove the line with 'sort'.

JS code:

map = function() {
for (var key in this) {
emit(key,

{count : 1}

)
}
}

reduce = function(key, emits) {
total = 0
for (var i in emits)

{ total += emits[i].count }

return

{count : total}

}

db.runCommand(
{ mapreduce : 'test',
map : map,
reduce : reduce,
out :

{ inline : 1 }

,
query : { $exists :

{B : true}

},
sort :

{ B : 1 }

}
);

Comment by Robert Stam [ 21/May/12 ]

Sorry, I missed your point that the existing unit tests could be modified to give the same error. Will try that in the morning (and/or use your attached program). Thanks.

Comment by Roman Kuzmin [ 21/May/12 ]

Robert, I will try this in the shell as soon as I can (I'm very lame in the shell, btw).

As for the request for more information, the attached program has it all, it creates all that it needs. Also, you can use the existing test TestMapReduceInlineWithQuery and replace one line as I suggested.

Comment by Robert Stam [ 21/May/12 ]

Two requests:

1. Can you try the same map/reduce in the mongo shell to see if the C# driver has anything to do with this
2. And if so, can you provide more information to reproduce (sample documents, indexes defined, map/reduce functions...)

Thanks.

Comment by Robert Stam [ 21/May/12 ]

I assume the corresponding question on Google Groups is:

https://groups.google.com/forum/?fromgroups#!topic/mongodb-user/SwULp7Y6oSY

Generated at Wed Feb 07 21:36:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.