I have an application that is trying to query a MongoDB collection using a BSON Document and the ‘limit’ option does not work. The application is using the MongoDatabase.runCommand(Document) call. I got the BSON parser to accept the document text (thanks to https://docs.mongodb.com/manual/reference/command/find/#dbcmd.find) but the limit does not seem to be used when performing the query. I get all matching results back no matter what I set the limit option to. Has anyone else run into this issue? The application I am working with does not want to use straight Java calls to the .limit(int) method if it can be avoided.
The BSON Document:
{
find: 'InformationCollection',
filter: {
'INFORMATION.LONG_ATTRIBUTES.fieldOne': 12345
},
sort: {
TIMESTAMP: -1
},
limit: 1,
projection: {
_id: 0
},
allowDiskUse: true
}