首页 > 数据库技术 > 详细

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

时间:2018-04-02 19:05:24      阅读:227      评论:0      收藏:0      [点我收藏+]


代码:

 

    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.

原文:https://www.cnblogs.com/sy-liu/p/8695990.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!