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

comment cannot be used with findOneAndUpdate #11793

Closed
arthur-guesty opened this issue May 11, 2022 · 1 comment
Closed

comment cannot be used with findOneAndUpdate #11793

arthur-guesty opened this issue May 11, 2022 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@arthur-guesty
Copy link

Hi, currently when trying to apply comment to a findOneAndUpdate query it results in an error of:

comment cannot be used with findOneAndUpdate

The exact query I am trying:
this.quoteModel.findOneAndUpdate( { _id: new mongoose.Types.ObjectId(quoteId) }, newQuoteObj, { upsert: true, session}, ).comment("abcde");

When looking into the documentation of findAnyModify I see that comment is supported:
https://www.mongodb.com/docs/manual/reference/command/findAndModify/

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

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({
    name: String
});

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

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

    const entry = await Test.create({ name: 'test' });

    await Test.findOneAndUpdate({_id: new mongoose.Types.ObjectId(entry.id)}, {name: 'Test'}).comment('abcde');
    console.log('done');
}

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