google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

Update a query with order #294

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia/Driver/MongoDB)

Morphia: 1.00-snapshot
driver: 2.5.3

Please include a stack trace below:

When I update a query which has an order, the Morphia throws an error:

    QueryException occured : sorting is not allowed for updates. 

My code is:

    class User {
        public Query<Message> queryUnreadMessages() {
            ds.createQuery(Message.class).filter("read =", false).order("read, -created_at");
        }
    }

Now I want to set all the unread messages as "read", so I write:

    Query<Message> messages = user.queryUnreadMessages();
    ds.update(messages, createUpdateOps().set("read", true));

Then that exception thrown.

If I remove the "order" part from the query, it will be fine. But this is 
inconvenient, since most of time, I need that query with the order. 

In order to update it, I have to write another method called 
"queryUnreadMessageWithoutOrder()", because I don't find a way to remove the 
order from the query.

I hope morphia will check the order first, and remove it if it presents, before 
updating.

Original issue reported on code.google.com by nowind...@gmail.com on 5 Jul 2011 at 4:44

GoogleCodeExporter commented 9 years ago
And also the "ds.delete(query)"

Original comment by nowind...@gmail.com on 5 Jul 2011 at 4:48

GoogleCodeExporter commented 9 years ago
This is not allowed on the server. When it supported there we can allow it.

For now I will add a method to reset the order so you can clone/change the 
query and reuse.

Original comment by scotthernandez on 5 Aug 2011 at 9:51

GoogleCodeExporter commented 9 years ago

Original comment by scotthernandez on 5 Aug 2011 at 9:58