Skip to content

Using the all positional operator $[] in nested arrays causes an error #407

@Shelagh-Lewins

Description

@Shelagh-Lewins

Hi, I don't know if this is a bug in simple schema or if I'm doing something wrong.

I have a nested array like this:

myGrid = [
[1,0,2,3],
[2,2,0,1].
]

My schema is like this:

const MyCollectionSchema = new SimpleSchema({
'myGrid': {
	'type': Array,
},
'myGrid.$': {
	'type': Array,
},
'myGrid.$.$': {
	'type': SimpleSchema.Integer,
},
});

And I am updating the array like this:

const update = {};
update.$push = {
	'myGrid.$[]': {
		'$each': [3,2,3],
		'$position': 2,
	},
};

MyCollection.update({ _id }, update);

This inserts the new values [3,2,3] into each child array at position 2, as per the docs.
(I'm using this form because I'm performing multiple updates in one operation, but I've left out the other updates from this example.)

When I run the code I see this error:

Exception ...{ Error: myGrid.$[] is not allowed by the schema (myGrid.$[])

If I bypass Collection2 like this, the operation succeeds:

MyCollection.update({ _id }, update, { 'bypassCollection2': true });

Is there a way to make this operation pass the schema? Or is it a bug? Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions