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

New version error #10624

Closed
wioniqle-q opened this issue Aug 27, 2021 · 5 comments
Closed

New version error #10624

wioniqle-q opened this issue Aug 27, 2021 · 5 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@wioniqle-q
Copy link

image
image
image

Why this error? no errors in older versions

@IslandRhythms IslandRhythms added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Aug 27, 2021
@IslandRhythms
Copy link
Collaborator

Please include the code that is throwing the error

@wioniqle-q
Copy link
Author

@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Aug 27, 2021
@vkarpov15 vkarpov15 added this to the 6.0.3 milestone Aug 27, 2021
@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Aug 27, 2021
@IslandRhythms
Copy link
Collaborator

I'm getting the same thing when I run it on mongoose latest

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({
    Id: String,
    Auth: {type: Boolean, default: false},
    Usage: {type: Object, default: {} }
});

const Test = mongoose.model('Test', testSchema);

    

async function test() {
    await mongoose.connect('mongodb://localhost:27017/test', {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      });
      await mongoose.connection.dropDatabase();
      await Test.updateOne({ Id: '12344566', Auth: true}, { $inc: {"Usage.Man": 1 } }, {upsert:true})
      
      console.log('Done');
}


test();

@wioniqle-q
Copy link
Author

I'm getting the same thing when I run it on mongoose latest

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({
    Id: String,
    Auth: {type: Boolean, default: false},
    Usage: {type: Object, default: {} }
});

const Test = mongoose.model('Test', testSchema);

    

async function test() {
    await mongoose.connect('mongodb://localhost:27017/test', {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      });
      await mongoose.connection.dropDatabase();
      await Test.updateOne({ Id: '12344566', Auth: true}, { $inc: {"Usage.Man": 1 } }, {upsert:true})
      
      console.log('Done');
}


test();

Thank you, its works, have a good night :)

@vkarpov15 vkarpov15 modified the milestones: 6.0.3, 6.0.4 Aug 30, 2021
@vkarpov15 vkarpov15 reopened this Aug 30, 2021
@vkarpov15
Copy link
Collaborator

To work around this, set setDefaultsOnInsert to false:

await Test.updateOne({ Id: '12344566', Auth: true}, { $inc: {"Usage.Man": 1 } }, {
  upsert:true,
  setDefaultsOnInsert: false // Tell mongoose to not add `$setOnInsert: { Usage: {} }` to the update
})

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