Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Mongo Basics Working With Collections Querying Collections

Different Mongo Response to "$or" Query

When I ran the exact $or command string exactly as Huston, Mongo returned "..." on the next line, but never finished or changed as first I thought it may have been a default sign of the database thinking or querying. Please explain. Thanks!

Dennis Brown
Dennis Brown
28,742 Points

Whenever you see the "..." on the next line, it means that there is an open bracket or curly brace in the query. When using an operator like $or, an extra set of of brackets is needed to add an array of conditional expressions, with a set of braces around each expression, but if you leave one of these open at the end, Mongo Shell will interpret that as the query not being completed.

The reason this is even an option is so that you can create complex queries with multiple lines like so:

db.collection.find({
  _id: 'someid',
  $or: [
    { $title: /How/ },
    { $title: /101/ }
  ]
},
{
  title: true,
  id: false
});

A good way to keep this issue from happening, is to always type the opposite bracket/brace with the first when typing out your queries; I am actually surprised that Mongo Hacker doesn't do this for you.

Neil McPartlin
Neil McPartlin
14,662 Points

Thank you Dennis Brown. Perfect explanation. If you were to add this again as an 'answer', I'd happily give you an upvote. And if Gavin Schilling likes it too, he might even give you a 'best answer' :)