Skip to content

Commit 3f4991d

Browse files
committed
Working ORDERBY implementation
1 parent 380ade4 commit 3f4991d

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/main/java/picoded/dstack/mongodb/MongoDB_DataObjectMap.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,22 +396,20 @@ public String[] query_id(Query queryClause, String orderByStr, int offset, int l
396396
// The final sorting BSON
397397
Document sortBson = new Document();
398398

399-
// Normalize it first
400-
orderByStr = (new OrderBy(orderByStr)).toString();
401-
402399
// Split it accordingly
403400
String[] orderSeq = orderByStr.split(",");
404401
for(int i=0; i<orderSeq.length; ++i) {
405402
String subSeq = orderSeq[i];
403+
String subSeq_uc = subSeq.toUpperCase();
406404

407-
// This safely handles both ASC, and DESC sequence
408-
String field = subSeq.substring(0, subSeq.length()-4).trim();
409-
410405
// Append the order by rule accordingly
411-
if( subSeq.endsWith("ASC") ) {
412-
sortBson.append(field, 1);
406+
if( subSeq_uc.endsWith("ASC") ) {
407+
sortBson.append( subSeq.substring(0, subSeq.length()-3).trim(), 1 );
413408
} else if( subSeq.endsWith("DESC") ) {
414-
sortBson.append(field, -1);
409+
sortBson.append( subSeq.substring(0, subSeq.length()-4).trim(), -1 );
410+
} else {
411+
// DEFAULT is ASC
412+
sortBson.append( subSeq.trim(), 1 );
415413
}
416414
}
417415

0 commit comments

Comments
 (0)