MongoDB and Spring Data – simple fixes, no digging

This is here as much as a placeholder for myself as info for anyone else.  This is a list of minor and medium issues I’ve had working with MongoDB that were not instantly findable in a google search.

* “ns doesn’t exist”

In this case I was using MongoDB locally with a Spring Data connector.  I suppose the ‘ns’ here probably means “namespace”…not the most well thought out error.  The error, should you come across it might look like this:

Caused by: com.mongodb.CommandResult$CommandFailure: command failed [mapreduce]: { “serverUsed” : “localhost/″ , “errmsg” : “ns doesn’t exist” , “ok” : 0.0}
at com.mongodb.CommandResult.getException(
at com.mongodb.CommandResult.throwOnError(
… 35 more

The actual problem is that the specified collection name doesn’t exist in the database you are configured to talk to .  Verify the database and collection name to solve the problem.

* Logging with the JS in a map-reduce job

Surpassingly difficult to find the answer to this, or I just suck at searching.  Searching the mongo site itself for ‘mapreduce logging’ or ‘print’ didn’t yield clear results.

It is really, really simple.

…js code…;print(“some debug” + debug); …more js code…

The content will flush out the mongodb log…which hopefully you have access to…

* How do I get my oid in a spring mapreduce job so I have access to the timestamp?

I couldn’t figure this one out.  Add a to your json constructs.  I think it’s cause spring jacks with that ID.