Nebulent - software solutions

Nebulent

Edie (Enterprise Data Intelligence Engine) is our latest application that is specifically designed to help organization get up to speed with Amazon Mechnical Turk platform without going through a learning curve. No need to code or manage any spreadsheets. Design your tasks and push your data through our qualified work force to get fast results at fraction of a penny.

Contacts

Contact information

Toll Free: +1(888)201-7922

Blog

Spring Data with Mongo hint command

Quiet often, MongoDB fails to use existing indexes based on the supplied queries (found out the hard way), but it is possible to force MongoDB using a certain index with “hint” command. To do this in Spring Data, follow example below:

{code}
public List<Performance> searchPerformancesByTitle(String accountUUID, String title) {
Query orQuery1 = Query.query(Criteria.where(“title”).is(new BasicDBObject(“$regex”, title).append(“$options”, “i”)));
Query orQuery2 = Query.query(Criteria.where(“fileName”).is(new BasicDBObject(“$regex”, title + “$”)));
Query query = new Query().or(new Query[]{orQuery1, orQuery2});
query.fields().include(NATIVE_RECORDING_UUID).include(“title”).include(“duration”).include(“genre”).include(“artist”).include(“fileName”); //.include(“album”).include(“year”).include(“comment”);
query.limit(getMaxTitleSearchMatches());
return getMongoTemplate().find(query, Performance.class, new CursorPreparer() {

@Override
public DBCursor prepare(DBCursor cursor) {
cursor.hint(“tile_fileName_index”);
return cursor;
}
}, accountUUID);
}

{code}

2011-08-20