I am having trouble saving a new object, as one of the fields is not being saved even though all others are saved successfully.
In my Mongoose schema, I have defined a property called superPlotId:
const mongoose = require('mongoose');
const GeoJSON = require('mongoose-geojson-schema');
const Schema = mongoose.Schema;
const plotSchema = new Schema(
{
...fields...
superPlotId: String,
...more fields
},
{ strict: false },
{ bufferCommands: false }
);
//create model class
const ModelClass = mongoose.model('plot', plotSchema);
//export model
module.exports = ModelClass;
When trying to save a new object that adheres to this schema using Express, I do it like this:
exports.newPlot = async (req, res, next) => {
const {
...a bunch of fields...
superPlotId
} = req.body.props;
const plot = new Plot({
...a bunch of fields...
superPlotId
});
console.log(('new plot:', JSON.stringify(plot)));
try {
const newPlot = await plot.save();
res.json(newPlot);
} catch (e) {
console.log("couldn't save new plot", JSON.stringify(e));
return res.status(422).send({ error: { message: e, resend: true } });
}
};
Despite confirming that a correctly formatted object is reaching the endpoint through the console.log above:
{...bunch of fields..."superPlotId":"5a9e9f9f0f8a8026005fe1e7"}
The plot in the database does not include the superPlotId field.
If anyone has insight into what might be causing this issue, please let me know!