I am trying to add an extra field to a collection of objects, the class is called Product.
I've printed the number of updates results with results.getUpdatedCount()
and this gives the proper result, so it looks like something is happening.
So I suspect that you cannot do a "bulk update" on a new field. I.e. it thinks it's doing something hence no error is thrown, but in actual fact nothing happens. But this seems pretty unlikely, do you have any ideas?
The morphia docs I've used are here: https://github.com/jmkgreen/morphia/wiki/Updating
My code looks like this:
public void updateStatusToOld(String val){
Datastore ds = Dao.instance().getDatabase();
UpdateOperations<Product> ops;
Query<Product> query = ds.createQuery(Product.class).field("key").equal(val);
ops = ds.createUpdateOperations(Product.class).set("status", "OLD");
UpdateResults<Product> results = ds.update(query, ops);
}