I am trying to create a Node.js API endpoint to return some values for population of a select control.
I have the following document in a collection called projectStatusValues...
{
"_id": {
"$oid": "5cab4b2b38802527df2f7ab2"
},
"projectStatusDesc": [
"Complete",
"Pre-Start",
"Active"
]
}
And my Mongoose model is defined as...
const projStatusModel = mongoose.model("projectStatusValues", {
"projectStatusDesc": [
String
]
});
The finally, I'm using this code to retrieve the array values...
app.get('/v1/projStatus', async (request, response) => {
try {
var status = await projStatusModel.find().exec();
response.send(status);
} catch (error) {
response.status(500).send(error);
}
});
The endpoint looks good and I get a 200 response but an empty string is returned. Any ideas?
Thanks!
答案 0 :(得分:1)
You are missing Schema
const Schema = mongoose.Schema;
const projStatusModel = mongoose.model("projectStatusValues", new Schema ({
"projectStatusDesc": [
String
]
}));
答案 1 :(得分:0)
将集合从projectStatusValues重命名为projectstatusvalues,并且可以正常工作。