Wednesday 30 November 2016

Mongoose returning an empty object?

I have a search api that you can search using the imgur api and it'll return json data of the images, but will also record your latest search in the "/latest" url. The only problem is it returns an empty object no matter what I do. Anyone know why this is?Whole file: http://ift.tt/2fDrfkJ code that may be not allowing it: index.js router.get("/latest", function (req, res) { History.find({}, 'term when -_id').sort('-when').limit(10).then(function (results) { res.json(results); }); }); router.get("/search/:q", function (req, res) { imgur.getImage(req.params.q, req.query.offset).then(function (ans) { new History({ term: req.params.q }).save(); res.json(ans); }); }); history.jsvar historySchema = new mongoose.Schema({ term: String, when: { type: Date, default: Date.now } }); var History = mongoose.model("History", historySchema);

Submitted November 30, 2016 at 03:07PM by jeff_64

No comments:

Post a Comment