Morphia / MongoDb Usage and Indexing with FindAndModify ()

I am currently refactoring some of our mango query code to get rid of methods deprecated in Morphia 1.3. I am having a problem when I try to search and Modify a query with an index. At the moment, our legacy code sets the index for the query like this: ds.createQuery(Entity.class).hintIndex("index")

I removed it to match morphia 1.3 and now the code looks something like this: new FindOptions.modifier("$hint", "index"); return query.asList(findOptions);

As a result, we do not set the index in the query until we actually run it. This is fine for receiving requests, much less upsert. To replace the deprecated findAndModify : findAndModify(Query<T> query, UpdateOperations<T> operations, boolean oldVersion, boolean createIfMissing)

, morphia asks to usefindAndModify(Query, UpdateOperations, FindAndModifyOptions)

In this case, I would expect to have a modifier method on the object FindAndModifyOptions

to be able to set the index when the query is executed. I can't seem to do something like this:

FindAndModifyOptions findOptions = new FindOptions();
findOptions.modifier("$hint", SUGGESTION_CONTENT_TYPE_INDEX_NAME);
return datastore.findAndModify(query, updateOperations, findAndModifyOptions);

      

Can anyone advise on how to traverse the index? Can this be done using the FindAndModifyOptions object? If not, what would be the best way to set the index for the upsert request

+3


source to share





All Articles