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

orFail() does not work with replaceOne() #10963

Closed
8NAF opened this issue Nov 9, 2021 · 1 comment
Closed

orFail() does not work with replaceOne() #10963

8NAF opened this issue Nov 9, 2021 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@8NAF
Copy link

8NAF commented Nov 9, 2021

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

What is the current behavior?
Calling replaceOne() with orFail() does not throw an exception.

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

const SharkSchema = new mongoose.Schema({
    weight: Number,
    length: Number,
})
const Shark = mongoose.model('Shark', SharkSchema)

const result = await Shark
    .replaceOne({ weight: 1 }, { weight: 2, length: 3 })
    .orFail()
    .catch(e => e)

console.log(result)
/*{
    acknowledged: true,
    modifiedCount: 0,
    upsertedId: null,
    upsertedCount: 0,
    matchedCount: 0
} */

What is the expected behavior?
An error should be thrown if the no document was found.

What are the versions of Node.js, Mongoose and MongoDB you are using?
NodeJS: 16.13.0
Mongoose: 6.0.12
MongoDB: 4.4.10

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Nov 9, 2021
@IslandRhythms
Copy link
Collaborator

const mongoose = require('mongoose');

const SharkSchema = new mongoose.Schema({
    weight: Number,
    length: Number,
})
const Shark = mongoose.model('Shark', SharkSchema)

async function run() {
    await mongoose.connect('mongodb://localhost:27017/', {useNewUrlParser: true,
    useUnifiedTopology: true,});
    await mongoose.connection.dropDatabase();
    const result = await Shark
    .replaceOne({ weight: 1 }, { weight: 2, length: 3 })
    .orFail()
    .catch(e => e)

console.log(result)
}

run();

@vkarpov15 vkarpov15 added this to the 6.0.14 milestone Nov 15, 2021
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