Reputation: 77
I migrated my api code to a new server couple of days back and installed all the latest packages for mongoose, express, etc. Previously, I ran the same query with mongoose version 4.12.3 and everything worked fine. But, now when I run the same query with all the upgraded packages sort() and limit() don't work.
This is the code for my api controller
'use strict';
var mongoose = require('mongoose'),
Quad = mongoose.model('Quad');
exports.list_machine_quadData = function(req, res) {
Quad.find({"machineId":req.body.machineId}, function(err, quad) {
if (err)
res.send(err);
res.json(quad);
}).sort({"data.eTimeStamp":-1}).limit(96);
};
and this is the schema for the same
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const QuadSchema = new Schema({
eDate:{
type: Date,
required: [true,'eDate is required']
},
eTimeStamp:{
type: Date,
required: [true,'eTime is required']
},
dataJ:{
type: String,
required: [true,'DataJ is required']
}
});
const DataSchema = new Schema({
clientId:{
type: String,
required: [true,'Client ID is required']
},
machineId:{
type: String,
required: [true,'Machine ID is required']
},
data:[QuadSchema]
});
const Quad = mongoose.model('Quad',DataSchema);
module.exports = Quad;
were there any changes made to the sort() query and limit() in 5.X. If so, what do I need to change to make my code work? Thank you :)
Upvotes: 0
Views: 3086
Reputation: 1064
You need to change your mongoose query
Replace this code
Quad.find({"machineId":req.body.machineId}).sort({"data.eTimeStamp":-1}).limit(96).exec(function(err, quad) {
if (err)
res.send(err);
res.json(quad);
});
Upvotes: 2