Archive for: November, 2011

MongoDB: can only have 1 index plugin / bad index key pattern

MongoDB: can only have 1 index plugin / bad index key pattern

While working with MongoDB and the MongoDB Java driver I got the following exception when attempting to iterate over a result set.

com.mongodb.MongoException: can only have 1 index plugin / bad index key pattern
at com.mongodb.MongoException.parse(MongoException.java:82)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:312)
at com.mongodb.DBCursor._check(DBCursor.java:369)
at com.mongodb.DBCursor._hasNext(DBCursor.java:498)
at com.mongodb.DBCursor.hasNext(DBCursor.java:523)

This exception drove me nuts. I checked the index definition in Java, which looked fine, compared it to the index result in Mongo shell (db.collectionName.getIndexes()), which looked fine too, made several desperate attempts to drop and recreate the index, re-index the collection, etc.

Then I cut down the DB query and recognized that removing my sort() call made a difference. Eventually it turned out that the sort order was specified as a String instead of an Integer, see below:

BasicDBObject query = ...
// WRONG:
// BasicDBObject sort = new BasicDBObject("column1", "1").append("column2", "-1");
// RIGHT:
BasicDBObject sort = new BasicDBObject("column1", 1).append("column2", -1);
mongoDB.getCollection("collectionName").find(query).sort(sort);
Using Grails without a database

Using Grails without a database

If you’re using Grails for a frontend without direct database access, there are four things you need to do.

  1. Remove Grails’ Hibernate plugin.
    grails uninstall-plugin hibernate
  2. Delete the datasource configuration file conf/DataSource.groovy
  3. Explicitly declare services as non-transactional. The default is true and your class methods would be proxied, but without the Hibernate plugin there is no transaction manager and the deployment will fail.
    class SomeService {
    	static transactional = false
    	// ...
    }
  4. Use command objects instead of domain objects, particularly if you need validation.

9 out of 10 startups fail

Disclaimer: I’ve chosen a rather provocative title for this posting. It has no qualified basis but it’s something you hear very often in one way or another. 7 out of 10 fail, 9 out of 10 fail, etc.

I was interested in whether there’s any truth in this startup-scene meme, so I took some time to walk through 13 startups who presented 30 second pitches at Web 2.0 summit 2010, a little more than one year ago.

Here’s the outcome – all startups in the order of appearance with a number of open permanent positions at the time of this writing.

I’ve just put a reminder in my calendar to revisit this list in one year. Let’s see how it’s looking like then.

Deprecation of ConfigurationHolder in Grails 2

Deprecation of ConfigurationHolder in Grails 2

While porting my Grails applications to 2.0 RC1, I recognized that ConfigurationHolder is now deprecated. The new way to access the configuration is through dependency injection of the grailsApplication bean.

Before 2.0:

import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH
...
def value = CH.config.my.configEntry

With 2.0:

class MyService/MyController {
	def grailsApplication
	def method {
		def value = grailsApplication.config.my.configEntry
	}
}