exports.index = function(req, res) {
moviedb.indexMovie().then(function(){
console.log("DATABASE VALUES READ SUCCESSFULLY");
});
};
var moviedb = module.exports = {
indexMovie : function() {
return new P(function(resolve, reject){
MovieEntry.removeAsync({})
.then (function() {
return P.map(movieJson, x => movieApi.searchMovies(x.name)).map(x => {
return new MovieEntry({
id: x.id,
title : x.title,
originalTitle : x.originalTitle,
year : x.year,
popularity : x.popularity,
voteAverage : x.voteAverage,
votes : x.votes,
isAdult : x.isAdult,
video : x.video,
poster : x.poster,
backdrop : x.backdrop,
});
}).map(x => x.save())
.then(x => console.log("All tasks completed successfully!"))
.catch(e => { console.error("An error occurred", e); throw e; });
})
})
}
}
I am encountering an issue where the log "DATABASE VALUES READ SUCCESSFULLY" is not being displayed. Despite this, the indexMovie function runs without any errors. Can someone advise me on what might be causing this? I am uncertain about how promises work in this context and want to make sure that I can read from the database after the write operations are complete.