org.mongodb.morphia.query.QueryException: sorting is not allowed for updates.

Posted 三里路

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了org.mongodb.morphia.query.QueryException: sorting is not allowed for updates.相关的知识,希望对你有一定的参考价值。


代码:

 

    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"); 


以上是关于org.mongodb.morphia.query.QueryException: sorting is not allowed for updates.的主要内容,如果未能解决你的问题,请参考以下文章