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

6.x erroring with $not cannot be empty when using $size operator #10716

Closed
adamreisnz opened this issue Sep 13, 2021 · 2 comments
Closed

6.x erroring with $not cannot be empty when using $size operator #10716

adamreisnz opened this issue Sep 13, 2021 · 2 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@adamreisnz
Copy link
Contributor

adamreisnz commented Sep 13, 2021

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

What is the current behavior?
Unable to query for documents using {someArray: {$not: {$size: 0}}}

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

const mongoose = require('mongoose')
const {Schema} = mongoose
const uri = `mongodb://localhost:27017/test`
console.log(`Mongoose version: ${mongoose.version}`)

const BarSchema = new Schema({
  bar: {
    type: String,
  },
})

//Schema
const FooSchema = new Schema({
  foo: {
    type: String,
  },
  bars: [BarSchema],
})

//Model
const Foo = mongoose.model('Foo', FooSchema)

//Test function
async function test() {

  //Connect to database
  await mongoose.connect(uri)

  //Create new item
  const foo = new Foo({
    foo: 'foo',
    bars: [
      {
        bar: 'bar1',
      },
      {
        bar: 'bar2',
      },
    ],
  })
  await foo.save()

  //Query
  const foos = await mongoose
    .model('Foo')
    .find({bars: {$not: {$size: 0}}})

  console.log(foos)
}

test()

What is the expected behavior?
To find the document:

image

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Mongoose 6.0.5
MongoDB shell version v4.2.8
NodeJS 16.3.0

This was working ok in Mongoose 5.x

@vkarpov15 vkarpov15 added this to the 6.0.7 milestone Sep 15, 2021
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Sep 15, 2021
@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 Sep 15, 2021
vkarpov15 added a commit that referenced this issue Sep 15, 2021
@vkarpov15
Copy link
Collaborator

Fixed by #10730, fix will be in 6.0.7 👍

@adamreisnz
Copy link
Contributor Author

Thank you

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