exports.index = function(req, res) {
   moviedb.indexMovie().then(function(){
       console.log("READ VALUES FROM DATABASE");
  }); 
};
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 Done!"))
                                       .catch(e => { console.error("Error somewhere", e); throw e; });
                                    })
                            })
                    }       
                } 
I never get to see the log- "READ FROM DATABASE". However the function indexMovie executes perfectly. What am I doing wrong. I am not too sure about how the promise is working. I want to ensure that once the db writes are done i can read from database in the then call.
 
    