Home > Enterprise >  MongoDB question: Using $and and $or queries to read database with 1 $and and multiple $or
MongoDB question: Using $and and $or queries to read database with 1 $and and multiple $or

Time:12-30

Trying to solve the optional task at Codecademy's MongoDB course and unable to solve the 3rd question - In listingsAndReviews, find entries in the borough "Bronx" that serve one of the following cuisines: "Juice, Smoothies, Fruit Salads", "Spanish", or "Pizza". Does a comma separate $and and $or? Please help, thank you!

My solution:

db.listingsAndReviews.find( { $and: [ {borough: "Bronx}, { $or: [cuisine: "Spanish"}, {cuisine: "Juice, Smoothies, Fruit Salads"},{cuisine: "Pizza"}]}]})

SyntaxError: Unexpected token, expected "," (1:75)

CodePudding user response:

You don't need $and and $or. You can solve it with $in:

db.listingsAndReviews.find({
  borough: "Bronx",
  cuisine: { $in: ["Spanish", "Juice, Smoothies, Fruit Salads", "Pizza"] }
}
  • Related