Mongo BSON Query Limit Not Working?

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
	  }

Turns out something later in the code was overwriting the limit value immediately prior to the actual call to the database. D’oh!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.