Marc Rasmussen Marc Rasmussen -3 years ago 113
Node.js Question

mongoose nothing happens when i try to insert

i have the following

schema
:

module.exports = function (mongoose) {
var playlist = mongoose.Schema({
title: String,
artist: String,
album: String,
time: Date
});

return mongoose.model('playlist', playlist);
};


And then i have the following code:

var PlayListModel = require('./schemas/playlist.schema.js')(mongoose);
musicItem.time = new Date();
mongoose.models.playlist().save(musicItem).then(function (result) {
mongoose.find({title: musicItem.title}, function (err, doc) {
if(!err)
{
console.log(doc);
}
else
{
console.log(err);
}
})
}, function (err) {
console.log(err);
})


However there is no console message an no error only the following warning when i start the server:

`open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html


Can anyone tell me what ive done wrong?

Answer Source

You can try following code:

 var PlayListModel = require('./schemas/playlist.schema.js')(mongoose);

 musicItem.time = new Date()
 var playListModel = new PlayListModel(musicItem);
 playListModel.save( (err, playList) => { 

     // save data in playList

     // find result
     PlayListModel.find({title: musicItem.title}, (err2, result) => {
         // result
     });
 ));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download