I'm stuck on developing a node.js application. I'm trying to model a musical scale, which has a name and a number of associated notes:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var scaleSchema = new Schema({
name: String,
displayName: String,
notes: [{type: String}]
});
module.exports = mongoose.model('Scale', scaleSchema);
However, I don't know how to "seed" or even access this model. I want to fill it with some scales which are only ever loaded in once. I know I can require this model and use new
to make new entries, but is there a specific part of the node application I have to put this in? Is there a certain best practise to be used? Am I doing this wrong?
I'm pretty confused here, but feel as though I almost have a grasp on how it works. Can someone point me in the right direction?
You can create new database entries like you create objects. Here is a seeder class as an example.
Then in another file you can call it and it will seed your db.
Hope this helps.
As for structure I like to have a folder called "seeders". In there I have a file called databaseSeeder.js which requires all other seeders like usersCollectionSeeder.js and then calls the functions.
Here is a sample structure I like to use.
https://github.com/NikolayKolibarov/ExpressJS-Development