I am new to this, but I am trying to understand why my GET request is returning an empty array even though I am sure that the Mongo database collection is not empty. Each word form in the WordForm collection has a "lexicalform" key that refers to a LexiconEntry object in that collection. When I make a GET request with a LexiconEntry ObjectId as a parameter, it returns an empty array instead of the actual array contents. Below are the relevant files:
The GET route in my controller:
api.get('/wordforms/:id', (req, res) => {
WordForm.find({lexiconentry: req.params.id}, (err, wordforms) => {
if (err) {
res.send(err);
}
res.json(wordforms);
});
});
The LexiconEntry model:
import mongoose from 'mongoose';
import WordForm from './wordform';
let Schema = mongoose.Schema;
let LexiconEntrySchema = new Schema({
lexicalform: String,
pos: String,
gender: String,
genderfull: String,
decl: String,
gloss: [String],
meaning: String,
pparts: [String],
tags: [String],
occurrences: Number,
wordforms: [{type: Schema.Types.ObjectId, ref: 'Form'}]
});
module.exports = mongoose.model('LexiconEntry', LexiconEntrySchema);
The WordForms model:
import mongoose from 'mongoose';
import LexiconEntry from './lexiconentry';
let Schema = mongoose.Schema;
let WordFormSchema = new Schema({
form: String,
gender: String,
case: String,
number: String,
lexicalform: {
type: Schema.Types.ObjectId,
ref: 'LexicalForm',
required: true
}
});
module.exports = mongoose.model('WordForm', WordFormSchema);