var foo = [ [ 14, 31, 55, 56, 60, 19 ], [30, 32, 33, 50, 64, 6 ], [9, 15, 22, 35, 48, 3] ];
var bar = await Model.find({
numbers: { $in: foo }
});
console.log(bar);
When I try to run the above code above I get the error below. The model is a mongoose model and the query runs with no problems in a raw mongodb query using robomongo.
{ [CastError: Cast to number failed for value "14,31,55,56,60,19" at path "numbers"]
message: 'Cast to number failed for value "14,31,55,56,60,19" at path "numbers"',
name: 'CastError',
kind: 'number',
value: [ 14, 31, 55, 56, 60, 19 ],
path: 'numbers',
reason: undefined }
model? Is the fieldnumbersdefined to be an array of the typeNumber? If so, it would fail.CastErroris simply because your schema is defined asNumberwhen you are in fact trying to compare "Arrays" being an array of numbers inside the$in. If you are saying this works without a schema involved the n perhaps your schema is incorrect for the data stored, since the"numbers"values themselves would be "arrays" rather than a single value defined in the schema. Your schema type should therefore be"numbers": [Number]and not"numbers": Numberas you likely have them defined.$alloperations inside an$orexpression. In that way the "sequence" of the numbers in the arrays does not need to be an "exact match" for the array as presented, but instead only needs to contain "all" the values in the list.