-
Hi, I'm trying to be able to make a model then save that model. Heres my code: let Homepage: mongoose.Model<mongoose.Document<any>>;
if (!mongoose.models.Homepage) {
const homepageSchema = new Schema({
configured: Boolean,
forums: {
type: Map,
of: Object
},
description: String,
store: Boolean,
storeLink: String,
website: Boolean,
websiteLink: String,
custom: Boolean,
customName: String,
customLink: String,
orgName: String
})
Homepage = mongoose.model('Homepage', homepageSchema)
}
const orgName = new Homepage({ configured: false });
await orgName.save()
return res.status(200).json(await mongoose.get('Homepage')) It's erroring all over the place (but no vscode errors strangely). How can I accomplish this? Also if you can show me a way where I can overwrite that, that would be great. (Like where I can plug in json values and it would edit the value in the schema, like |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
What are you trying to do with Maybe you're just trying to do |
Beta Was this translation helpful? Give feedback.
-
That works, but it keeps spamming my database (see image below). How can I save something then get back that same thing I saved in the database? Heres my code: Homepage = mongoose.model('Homepage', homepageSchema)
const orgName = new Homepage({ configured: true });
await orgName.save()
return res.status(200).json(await Homepage.findById(orgName)) |
Beta Was this translation helpful? Give feedback.
-
You should be able to do const orgName = await Homepage.create({ configured: true })
return res.status(200).json(orgName) Reference: https://mongoosejs.com/docs/api.html#model_Model.create |
Beta Was this translation helpful? Give feedback.
What are you trying to do with
await mongoose.get('Homepage')
?mongoose.get()
is a function for getting the current value of a global object.Maybe you're just trying to do
return res.status(200).json(orgName)
, orreturn res.status(200).json(await Homepage.findById(orgName))
?