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

JavaScript Using SQL ORMs with Node.js Performing CRUD Operations Attributes, Operators and Ordering

Why the bracket syntax in Op?

I don't understand the bracket syntax [Op.gte] below. Why not just Op.gte ? I know it doesn't work without the brackets, but not understanding why.

(async () => {
  await db.sequelize.sync({ force: true });

  try {

    // ... All model instances

    const movies = await Movie.findAll({
      attributes: ['id', 'title'],
      where: {
        releaseDate: {
          [Op.gte]: '2004-01-01' // greater than or equal to the date
    console.log( movies.map(movie => movie.toJSON()) );

  } catch(error) {

1 Answer

Shane Oliver
Shane Oliver
19,977 Points

A key in a JS object can only be a string. You can use computed property name syntax (square brackets) which allows you to put a JS expression that will be computed. In this case the value at object key Op.gte. You can use the square bracket notation to use template literals as well.