[JAVA-1147] Poor error message for find using sort Created: 12/Mar/14  Updated: 06/Apr/15  Resolved: 06/Apr/15

Status: Closed
Project: Java Driver
Component/s: Error Handling
Affects Version/s: 2.11.3
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Michael Bornholdt Nielsen [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7



 Description   

Performing a search in which data must be sorted and you insert "" as key you get a poor error message.

--------------------------------------------------------------------
MongoClient mongo = new MongoClient(new ServerAddress(host, port),
credentialList);
DB mongodb = mongo.getDB(DB_NAME)
DBCollection table = mongodb.getCollection(TABLE_NAME);
DBCursor cursor = table.find();
BasicDBObject orderBy = new BasicDBObject() ;
orderBy.put("", 1);
cursor.sort(orderBy);

--------------------------------------------------------------------
com.mongodb.MongoException: assertion d:\slave\windows_64bit_v2.4\mongo\src\mongo\db\../bson/bsonobjbuilder.h:92
at com.mongodb.MongoException.parse(MongoException.java:82)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:292)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
at com.mongodb.DBCursor._check(DBCursor.java:368)
at com.mongodb.DBCursor._hasNext(DBCursor.java:459)
at com.mongodb.DBCursor.hasNext(DBCursor.java:484)



 Comments   
Comment by Jeffrey Yemin [ 06/Apr/15 ]

The server now gives a better error message:

> db.test.find().sort({"" : 1})
Error: error: {
	"$err" : "Can't canonicalize query: BadValue bad sort specification",
	"code" : 17287
}

Comment by Jeffrey Yemin [ 12/Mar/14 ]

Thanks for the report. That error message is currently coming from the server, but the driver could easily detect the error before the query is every performed, and provide a better error message.

Generated at Thu Feb 08 08:53:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.