Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no cast function for nested 2dim arrays #13190

Closed
2 tasks done
rideckard opened this issue Mar 21, 2023 · 1 comment
Closed
2 tasks done

no cast function for nested 2dim arrays #13190

rideckard opened this issue Mar 21, 2023 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@rideckard
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.10.1

Node.js version

18.13.0

MongoDB server version

4.4.13

Typescript version (if applicable)

No response

Description

Using 2dimensional document array throws Error 'Base SchemaType class does not implement a cast() function' while executing mongodb query

Steps to Reproduce

const multiArraySchema = new Schema({
  label: String,
  arr: [Number]
})

const baseTestSchema = new Schema({
  baseLabel: String,
  mArr: [[multiArraySchema]]
})

const mArrB = mongoose.model('multiBArray', baseTestSchema)

const arrB = new mArrB({ baseLabel: 'testx', mArr: [[{ label: 'testInner', arr: [1, 2, 3, 4] }]] })
arrB.save().then(() => mArrB.updateOne({ baseLabel: 'testx' }, { $pullAll: { 'mArr.0.0.arr': [1, 2] } }))

Expected Behavior

the pullAll query to be executed

@vkarpov15 vkarpov15 added this to the 7.0.4 milestone Mar 21, 2023
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Mar 21, 2023
@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Mar 22, 2023
@IslandRhythms
Copy link
Collaborator

const mongoose = require('mongoose');
const { Schema } = mongoose;

const multiArraySchema = new Schema({
  label: String,
  arr: [Number]
});

const baseTestSchema = new Schema({
  baseLabel: String,
  mArr: [[multiArraySchema]]
});

const mArrB = mongoose.model('multiBArray', baseTestSchema);

async function run() {
  await mongoose.connect('mongodb://localhost:27017');
  await mongoose.connection.dropDatabase();
  const arrB = new mArrB({ baseLabel: 'testx', mArr: [[{ label: 'testInner', arr: [1, 2, 3, 4] }]] })
  await arrB.save();
  const res = await mArrB.updateOne({ baseLabel: 'testx' }, { $pullAll: { 'mArr.0.0.arr': [1, 2] } });
  console.log('what is res', res);

}

run();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants