diff --git a/lib/services/commands/commandRegistryMongoDB.js b/lib/services/commands/commandRegistryMongoDB.js index 31efedc3a..85c8ac149 100644 --- a/lib/services/commands/commandRegistryMongoDB.js +++ b/lib/services/commands/commandRegistryMongoDB.js @@ -41,7 +41,7 @@ function findCommand(service, subservice, deviceId, name, callback) { logger.debug(context, 'Looking for command [%s] for device [%s]', name, deviceId); - const query = Command.model.findOne(queryObj); + const query = Command.model.findOne(queryObj, null, { sort: { creationDate: -1 } }); query.select({ __v: 0 });