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:
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" : "",
	"Metascore" : "74",
	"imdbRating" : "7.2",
	"imdbVotes" : "97618",
	"imdbID" : "tt0398808",
	"Type" : "movie",
	"Response" : "True",
	"thumbsUp" : 0,
	"thumbsDown" : 0

Open in new window

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;

            } else {
                if (config.debug) util.log("Found nothing by that title - '" + title + "'..");
               responseHandler({Response: false});

Open in new window

So what I get as output only when searching for this particular movie is:
Found nothing by that title - 'Bridge To Terabithia'..
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
I guess the lookup in case sensitive then. The movie has a lowercase t in "to" where, based off the not found message that you posted, you are searching with an uppercase T in "To"
itniflAuthor Commented:
Bummer, is there a way to search in a non case sensitive way or lowercase both what I am searching for and the searxh string?
mccarlIT Business Systems Analyst / Software DeveloperCommented:
There is nothing that is easy/built-in to do that.

Are you able to change the schema of your database? If so, the most efficient way would be to add another field, that contains a lowercase (or uppercase) version of the title attribute, as well as the actual title. Then you can have that field indexed and then when you search, you can convert the search term to lower case and find the record that way. This is efficient as it can still properly use the index.

If not, there are methods to use regular expressions to do case-insensitive searches but these can be quite inefficient on large sets of data.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.