代码:
public UpdateResults updateProductByChannel(String channelId, String channelName){
Query<PixelProductModel> query = datastore.createQuery(PixelProductModel.class); query.order(“-create”); query.field(“channelId”).equal(channelId); UpdateOperations<PixelProductModel> operations = datastore.createUpdateOperations(PixelProductModel.class); operations.set(“channelName”,channelName); return datastore.update(query,operations); }
异常: org.mongodb.morphia.query.QueryException: sorting is not allowed for updates.
原因: Mongo不支持对更新操作进行排序,补偿或限制。 它确实支持对findAndModify操作进行排序,该操作也在 数据存储
解决办法: 去掉 query.order(“-create”);