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

$all condition transform to undefined #11314

Closed
DmytroMysak opened this issue Feb 2, 2022 · 0 comments
Closed

$all condition transform to undefined #11314

DmytroMysak opened this issue Feb 2, 2022 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@DmytroMysak
Copy link

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
I have a simple request with $all

const mongoose = require('mongoose');
const { ObjectId } = require('mongoose').Types;

mongoose.set('debug', true);

const { Schema } = mongoose;

async function run() {
  await mongoose.connect('mongodb://localhost:27017/testBug');

  await mongoose.connection.dropDatabase();

  const nested = new Schema({}, { id: true, _id: true });

  const schema = new Schema({ status: [nested] });
  const Test = mongoose.model('Test', schema);

  const id = new ObjectId();
  await Test.insertMany([
    { status: { _id: id } },
    { status: { _id: new ObjectId() } },
  ]);

  const result = await Test.find({
    status: {
      $all: {
        $elemMatch: { _id: id },
      },
    },
  });

  console.log(result);
}

run()
  .then(() => process.exit(0))
  .catch((err) => {
    console.log(err);
    process.exit(1);
  });

And mongoose send request like:
Mongoose: tests.find({ status: { '$all': [ undefined ] } }, { projection: {} })

If the current behavior is a bug, please provide the steps to reproduce.

To reproduce bug, just send query with $all (example in code)

What is the expected behavior?
In mongoose 6.1.8 everything work as expected
Here is output:
Mongoose: tests.find({ status: { '$all': [ { '$elemMatch': { _id: new ObjectId("61fabb8338f6907faa87655b") } } ] }}, { projection: {} })

Place to fix
Found this commit that broke $all behaviour

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Mongoose 6.1.10, MongoDB 4.4, Node v14.18.2

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Feb 2, 2022
@vkarpov15 vkarpov15 added this to the 6.2.1 milestone Feb 6, 2022
vkarpov15 added a commit that referenced this issue Feb 7, 2022
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