I have a background in SQL server and I'm migrating some data over to MongoDB for a proof of concept project using Mongoose as the driver. I want to add a DB ref to another collection. A basic example of what I'm trying to do here:
Project Schema:
{
projectNo: String,
projectTitle: String
}
Document Schema:
{
projectId: { type: mongoose.Schema.ObjectId, ref: 'project',
projectNo: String,
documentTitle: String
}
I want to add a new key to the Document schema that references the _id of the project collection. If I was doing this in SQL Server I'd do this:
UPDATE document
SET projectId = project._id
FROM project
WHERE document.projectNo = project.projectNo
Can anyone point me in the right direction? Thank you!
Kevin
Aucun commentaire:
Enregistrer un commentaire