Reputation: 1040
I have a JSON Object called parsedSong
that I want to convert into a Mongo document using Mongoose.
var newSong = new Song(parsedSong);
However, this only provides me with a new document that only has an id
attribute. How can I make a conversion that doesn't cut my data from parsedSong
?
Upvotes: 0
Views: 1084
Reputation: 1681
I assumed you have defined these variables in schema. Then you can make something like this:
var bestSong = {
artist: "Seether",
song: "Careless Whisper"
};
var song = new Song(bestSong);
song.save(function(err) {
if(err) throw err;
console.log('saved');
});
And now this song should be in database.
Upvotes: 1