PositiveGuy
PositiveGuy

Reputation: 20242

Is $or part of Mongo in a Meteor App?

I am assuming this is a mongo syntax thing. It's from a meteor app:

const { selectedSectionId } = this.state;

                const assignmentsSelector = {
                    formativeId: this.props.formative._id,
                    $or: [{ public: true }],
                 };

                 if (selectedSectionId && selectedSectionId !== 'all') {
                    assignmentsSelector.$or.push({ sectionId: selectedSectionId });
                 }

In the above what's the $or?

Upvotes: 0

Views: 42

Answers (1)

Bernard Lin
Bernard Lin

Reputation: 46

As defined in the MongoDB documentation:

The $or operator performs a logical OR operation on an array of two or more expressions and selects the documents that satisfy at least one of the expressions.

It appears that your $or array within assignmentsSelector only contains an expression to see if any document has a public property that is true. The conditional underneath the definition of assignmentsSelector provides the opportunity for you to add another expression to that array so that the $or operator will kick in.

For more on how $or behaves, visit the documentation here.

Upvotes: 2

Related Questions