itnifl
asked on
Can't fetch a document from MongoDB by its title attribute, but can find it in the database by the same attribute and value
I can find the movie in the mongodb database, but not when I search for it from nodejs. See the code below. This only happens with this movie title, none else.
This is what I get in my mongoDB database:
So what I get as output only when searching for this particular movie is:
Found nothing by that title - 'Bridge To Terabithia'..
This is what I get in my mongoDB database:
db.movies.findOne({"Title": "Bridge to Terabithia"})
{
"_id" : ObjectId("555f21f07eae877eeceb52c9"),
"Title" : "Bridge to Terabithia",
"Year" : "2007",
"Rated" : "PG",
"Released" : "16 Feb 2007",
"Runtime" : "96 min",
"Genre" : "Adventure, Drama, Family",
"Director" : "Gabor Csupo",
"Writer" : "Jeff Stockwell (screenplay), David Paterson (screenplay), Katherine Paterson (book)",
"Actors" : "Josh Hutcherson, AnnaSophia Robb, Zooey Deschanel, Robert Patrick",
"Plot" : "A preteen's life turns upside down when he befriends the new girl in school and they imagine a whole new fantasy world to escape reality.",
"Language" : "English",
"Country" : "USA, New Zealand",
"Awards" : "6 wins & 5 nominations.",
"Poster" : "http://ia.media-imdb.com/images/M/MV5BMTMzOTk1MzIyN15BMl5BanBnXkFtZTcwNTM3MjczMQ@@._V1_SX300.jpg",
"Metascore" : "74",
"imdbRating" : "7.2",
"imdbVotes" : "97618",
"imdbID" : "tt0398808",
"Type" : "movie",
"Response" : "True",
"thumbsUp" : 0,
"thumbsDown" : 0
}
When I run the following code from nodejs, I can fetch all movies by the title they have, except the movie named Bridge to Terabithia./**
* getMovie function.
* @param String title The title of the movie you are searching for
* @param {Function} responseHandler ResponseHandler Callback
* Returns a movie as JSON object
*/
MongoDB.prototype.getMovie = function(title, responseHandler) {
if (config.debug) util.log('Retrieving movie from mongodb: "' + title +'"');
this.db.collection('movies', function (err, collection) {
collection.findOne({ "Title": title }, function (err, movie) {
if (movie) {
if (config.verbosedebug) util.log("Found movie in mongodb: " + JSON.stringify(movie, undefined, 2));
if (config.debug) util.log("Found movie in mongodb: '" + movie.Title + "'..");
var thumbsUp = typeof movie.thumbsUp === undefined || isNaN(movie.thumbsUp) ? 0 : movie.thumbsUp;
var thumbsDown = typeof movie.thumbsDown === undefined || isNaN(movie.thumbsDown) ? 0 : movie.thumbsDown;
if(thumbsUp == 0) movie.thumbsUp = thumbsUp;
if(thumbsDown == 0) movie.thumbsDown = thumbsDown;
responseHandler(movie);
} else {
if (config.debug) util.log("Found nothing by that title - '" + title + "'..");
responseHandler({Response: false});
}
});
});
};
So what I get as output only when searching for this particular movie is:
Found nothing by that title - 'Bridge To Terabithia'..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER