MongoDB - Chain Search Query Helpers to Narrow Search Results

Tell us what’s happening:
Not sure what is wrong with my code, I did check the hint and follow it. The logs does not show anything relevant at well. I tried to change to different syntax for select or sort as in documentation and also assign a variable for Person.find() query before chaining methods but it also doesnt work. The notification in FCC log said that “Chaining query helpers should succeed”.

Your code so far

var queryChain = function(done) {
  var foodToSearch = "burrito";
  Person.find({ favoriteFoods: [foodToSearch] })
  .sort({ name: 1 })
  .select({ age: 0 })
  .exec(function(error, data) {
    if (error) return console.log(error);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/87.0.152 Chrome/81.0.4044.152 Safari/537.36.

Challenge: Chain Search Query Helpers to Narrow Search Results

Link to the challenge:

1 Like

Welcome, QuangTran.

Provided this is not an issue with Glitch, it might be useful to see the logs of the fCC console, when you submit the solution. That is:

  1. Go to this page:
  2. Open your browser dev tools
  3. Submit the project link
  4. See for output…

The console log in Chrome Dev tools does not show anything as well.

I do not think you are getting what you expect, because you have foodToSearch within []. If that does not work, do some debugging:

.exec(function(error, data) {
    if (error) return console.log(error);

Change it to {favoriteFoods: foodToSearch} did work though. Thanks a lot.

1 Like