Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

Does not work with `$[]` positional operator #424

Closed gwhobbs closed 3 years ago

gwhobbs commented 3 years ago

Does not work with MongoDB $[] positional insert/update operator, which updates all array matches starting in version 3.6.

To Reproduce

Steps to reproduce the behavior:

  1. Attempt to perform update operation using $[] positional operator
  2. See error such as actions.$[].completed is not allowed by the schema

Concrete example: mark all actions, stored in array on a MongoDB doc, as completed.

Relevant section of schema:

{
  ...,
  actions: { type: Array, optional: true },
  'actions.$': { type: Object, blackbox: true },
}

Query:

Actors.update({ 'actions.name': { $exists: 1 } }, { $set: { 'actions.$[].completed': true } })

Expected behavior

Every object in the actions array that has a name gets marked as completed.

Additional context

The $ positional operator works properly, but the $[] operator does not.

gwhobbs commented 3 years ago

Found existing issue #407