0

I have a variable "jobs" that contains an array of objects that looks something like this:

var jobs = [
{   
name: "Accountant"
score: 0,
}, {
name: "Actor"
score: 0,
}, {
name: "Actuary"
score: 0
}]

I am needing to save this jobs variable data to MongoDB.

What is the correct way to store data of this type with mongo? I've been attempting to use this set up without luck so far:

quizData: {
    type: mongoose.Schema.Types.ObjectId, 
    ref: "quizData"
},

1 Answer 1

1

you can store as field like as below ,

var mongoose = require('mongoose');
const Schema = mongoose.Schema;

var jobSchema = new Schema ({
    "jobs" : [{
      name : {type: String},
      score : {type : Number}
    }],
    //other key value
});

module.exports = mongoose.model('jobs' , jobSchema
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you! How would I go about actually getting the front end data into the model? For example how would I actually be able to add “accountant” from above?
I will get back to you tommorow . It midnight in india.
Thank you for the help!
Does your jobs will be have duplicate entries in database ? Can i know what are your plans and what do you expect from the schema jobs so according to it , will suggest the further changes @AndrewLeonardi
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.