Пн goose схема для импортируемой базы данных - PullRequest
1 голос
/ 03 марта 2020

Я экспортировал sql таблицы базы данных из DBeaver Community Edition в csv-файлы, а затем импортировал их в мою базу данных mongodb с помощью mongorestore.

Теперь я хочу запросить эту базу данных с помощью mon goose из моего приложения express, но хотя набранная схема выглядит точно так же, как запись json, которую я вижу в mongodb compass, запрос из mongosse, т.е. model.find () ничего не возвращает.

С чего начать устранение неполадок?

Образец документа:

    {
    "_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" : ""
}

файл моей схемы:

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);

функция запроса поиска:

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();
};

1 Ответ

2 голосов
/ 03 марта 2020

mon goose по умолчанию приумножить имя коллекции, поэтому вместо fish_final ожидается fish_finals, либо переименуйте имя коллекции в fish_finals, либо укажите имя коллекции как fish_final вручную в определении модели следующим образом:

 mongoose.model('your model name', fishSchema, 'fish_final'); 
...