[CSHARP-2048] OrderBy has stopped working for LINQ Queries in latest driver. Created: 28/Sep/17  Updated: 27/Oct/23  Resolved: 03/Oct/17

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.4.4
Fix Version/s: None

Type: Bug Priority: Blocker - P1
Reporter: Vijay Devappa Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 connecting to mongod version: 3.4.5 (WiredTiger) | SSL mode: preferSSL hosted at Mongo Labs


Attachments: PNG File mongo orderby date issue.PNG    

 Description   

I am surprised to see that ordering by date is not working properly no matter what I try on the latest C# driver. Pretty sure this was working before.

Here are some examples where dates are not ordered properly and coming out of sequence:

 
var row = mongoCollection.AsQueryable<EntityClass>()
                                     .OrderBy(p => p.MyDateTime.Value)
                                     .OrderBy(p => p.OtherId)
                                     .Where(p => p.MyId == myData.MyId)
                                     .FirstOrDefault();
 
var row = (from p in mongoCollection.AsQueryable<EntityClass>()
                  where p.MyId == myData.MyId
                  orderby p.MyDateTime.Value ascending
                  orderby p.OtherId ascending
                  select p).FirstOrDefault();
 
row = (from p in mongoCollection.AsQueryable<EntityClass>()
           where p.MyId == myData.MyId &&
                      p.OtherId > row.OtherId
           orderby p.MyDateTime.Value ascending
           orderby p.OtherId ascending
           select p).FirstOrDefault();

None of these work. I get dates out of sequence as shown in the attachment. I even tried adding an index on the date column in the server - made no difference.



 Comments   
Comment by Robert Stam [ 03/Oct/17 ]

Thanks for letting us know.

Comment by Vijay Devappa [ 28/Sep/17 ]

The issue can be closed. Answered in stacktrace. My bad:

https://stackoverflow.com/questions/46474865/orderby-has-stopped-working-for-linq-queries-in-mongodb-driver/46475068#46475068

Comment by Vijay Devappa [ 28/Sep/17 ]

Removing morelinq extension made no difference. Changes the property from DateTime? to DateTime made no difference. Tried downgrading to 2.3.0 driver version in nuget, made no difference.

Upgrading to mongod version: 3.4.9 (WiredTiger) made no difference.

Comment by Vijay Devappa [ 28/Sep/17 ]

The dates change from 4/20 to 4/21 to 4/19 and I see it get 4/18 later. Very strange.

Generated at Wed Feb 07 21:41:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.