Mongoose not returning data when MongoDB shell returns

44 views
Skip to first unread message

Mark Voris

unread,
Jun 12, 2019, 9:32:04 AM6/12/19
to Mongoose Node.JS ODM
I have been struggling where occasionally Mongoose doesn't return data even though if I manually run the query in MongoDB Compass and it works.  Here is my code

STUDIES.MODEL.JS
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const studySchema = new Schema({
region: String,
studyID: String,
locationName: String,
date: Date,
dayOfYear: Number,
volunteer: String,
inmateID: String,
inmateName: String,
notes: String
});

module.exports = mongoose.model('Studies', studySchema, 'studies');

const Study = require('../models/studies.model.js');
let filter = req.params.locationName;(being passed by Nodejs)
let visitDates = [];
let query = Study.find();
query.where({locationName: filter})
.exec(function (err, studies) {
visitDates.push({
date: studies.date,
dayOfYear: studies.dayOfYear,
volunteer: studies.volunteer,
inmateNumber: studies.inmateNumber,
inmateName: studies.inmateName
})
});


studies return with no data
Reply all
Reply to author
Forward
0 new messages