Reputation: 379
I exported sql database tables form DBeaver Community Edition in csv files and then imported them to my mongodb database using mongorestore.
Now i want to query this database with mongoose from my express app, but even though the schema i typed in looks exactly like the json entry i can see in mongodb compass, the query from mongosse i.e. model.find() returns nothing.
Where could I start to troubleshoot this?
Sample Document:
{
"_id" : ObjectId("5e5e40de4642404f824da649"),
"id" : 20,
"sampleid" : "WH0349/B09/17/14/LEEXT",
"station" : 17,
"cruise" : "WH0349",
"year" : 2011,
"month" : 12,
"day" : 13,
"fiarea" : "B09",
"species" : "Cod",
"group" : "LEEXT",
"fishno" : 14,
"sex" : "m",
"totallength" : 45,
"totalweight" : 706,
"latitude" : 55.1359,
"longitude" : 18.3204,
"bottomtemperature" : 5.05,
"bottomsalinity" : 10.73,
"bottomoxygensaturation" : 2.86,
"hydrographdepth" : "",
"fishdiseaseindex" : 0.9248,
"FDIAssessment" : "Y",
"cryp1" : 0,
"cryp2" : 0,
"cryp3" : 0,
"eppap1" : 0,
"eppap2" : 0,
"eppap3" : 0,
"finrot" : 0,
"locera1" : 0,
"locera2" : 0,
"locera3" : 0,
"pbt" : 0,
"skel1" : 0,
"skel2" : 0,
"skel3" : 0,
"ulc1" : 0,
"ulc2" : 0,
"ulc3" : 0,
"conditionfactor" : 0.77475995,
"CFAssessment" : "R",
"liverhistoindex" : 7,
"LHIAssessment" : "Y",
"headkidneylmspeak1" : 6,
"headkidneylmspeak2" : 25,
"headkidneylipofuscin" : 1.86,
"normgst" : "",
"normcat" : "",
"normgr" : "",
"normache" : "",
"musclecryo" : "",
"livercryo" : "",
"muclecwa" : "",
"musclecwaassessment" : "",
"detectedchemicalmuscle" : "",
"bilecwa" : "",
"bilecwaassessment" : "",
"detectedchemicalbile" : "",
"livercwa" : "",
"livercwaassessment" : "",
"detectedchemicalliver" : "",
"urinecwa" : "",
"blood1" : "",
"erythrocytes" : "",
"eryassessment" : "",
"hemoglobin" : "",
"hbassessment" : "",
"glocose" : "",
"gluassessment" : "",
"hematocrit" : "",
"hctassessment" : "",
"blood2" : "",
"plasma" : "",
"livercryotifi" : "",
"headkidneycryo" : "",
"kidneycryo" : "",
"liverhistoroutine" : "",
"histolivertumour" : "",
"histo" : "",
"gillcwaaverifin" : "",
"gillcwaassessmentverfifin" : "",
"otoliths" : ""
}
my schema file:
const mongoose = require('mongoose'),
Schema = mongoose.Schema;
let fishSchema = new Schema({
id: { type: Number },
sampleid: { type: String },
station: { type: Number },
cruise: { type: String },
year: { type: Number },
month: { type: Number },
day: { type: Number },
fiarea: { type: String },
species: { type: String },
group: { type: String },
fishno: { type: Number },
sex: { type: String },
totallength: { type: Number },
totalweight: { type: Number },
latitute: { type: Number },
longitude: { type: Number },
bottomtemperature: { type: Number },
bottomsalinity: { type: Number },
bottomoxygensaturation: { type: Number },
hydrographdepth: { type: String },
fishdiseaseindex: { type: Number },
FDIAssessment: { type: String },
cryp1: { type: Number },
cryp2: { type: Number },
cryp3: { type: Number },
eppap1: { type: Number },
eppap2: { type: Number },
eppap3: { type: Number },
finrot: { type: Number },
locera1: { type: Number },
locera2: { type: Number },
locera3: { type: Number },
pbt: { type: Number },
skel1: { type: Number },
skel2: { type: Number },
skel3: { type: Number },
ulc1: { type: Number },
ulc2: { type: Number },
ulc3: { type: Number },
conditionfactor: { type: Number },
CFAssessment: { type: String },
liverhistoindex: { type: String },
LHIAssessment: { type: String },
headkidneylmspeak1: { type: String },
headkidneylmspeak2: { type: String },
headkidneylipofuscin: { type: String },
normgst: { type: String },
normcat: { type: String },
normgr: { type: String },
normache: { type: String },
musclecryo: { type: String },
livercryo: { type: String },
musclecwa: { type: String },
musclecwaassessment: { type: String },
detectedchemicalmuscle: { type: String },
bilecwa: { type: String },
bilecwaassessment: { type: String },
detectedchemicalbile: { type: String },
livercwa: { type: String },
livercwaassessment: { type: String },
detectedchemicalliver: { type: String },
urinecwa: { type: String },
blood1: { type: String },
erythrocytes: { type: String },
eryassessment: { type: String },
hemoglobin: { type: String },
hbassessment: { type: String },
glocose: { type: String },
gluassessment: { type: String },
hematocrit: { type: String },
hctassessment: { type: String },
blood2: { type: String },
plasma: { type: String },
livercryotifi: { type: String },
headkidneycryo: { type: String },
kidneycryo: { type: String },
liverhistoroutine: { type: String },
histolivertumour: { type: String },
histo: { type: String },
gillcwaaverifin: { type: String },
gillcwaassessmentverfifin: { type: String },
otoliths: { type: String }
});
module.exports = mongoose.model('fish_final', fishSchema);
my find query function:
async (req, res) => {
let data = await fishModelFile.find({});
console.log('output some data', data);
res.write(JSON.stringify({ message: 'found data', data: data }));
res.end();
};
Upvotes: 1
Views: 288
Reputation: 17858
mongoose pluralize the collection name by default, so instead of fish_final
it expects fish_finals
, either rename the collection name to fish_finals or specify collection name as fish_final
manually in model definition like this:
mongoose.model('your model name', fishSchema, 'fish_final');
Upvotes: 2