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

[MONGODB DRIVER] DeprecationWarning: collection.findOneAndUpdate option [returnOriginal] is deprecated and will be removed in a later version #10285

Closed
kyrylkov opened this issue May 24, 2021 · 10 comments · Fixed by #10298
Assignees
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.

Comments

@kyrylkov
Copy link

No description provided.

@kakarot-dev
Copy link

i have the same prob

@fabraga
Copy link

fabraga commented May 25, 2021

Happening to me too. It must be from this latest version of mongoose (5.12.11) because I updated this today. I never placed option [returnOriginal] though.

@Jacint96
Copy link

Happening to me on mongoose (5.12.10) aswell

@IslandRhythms
Copy link
Collaborator

I'm gonna need a repro script from somebody because I can't reproduce it but enough of you are reporting this issue to cause concern.

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

PathToLife commented May 26, 2021

I'm gonna need a repro script from somebody

Hi just got it as well, narrowed it down to Model.findByIdAndUpdate.

not sure if it's typescript only

index.ts

import mongoose, { Schema } from 'mongoose'
import { MongoMemoryServer } from 'mongodb-memory-server'

const deprecateMe = new Schema({
    hello: Schema.Types.String,
})

const DeprecateMe = mongoose.model('yolo', deprecateMe)

const run = async () => {
    const mms = new MongoMemoryServer()
    const uri = await mms.getUri()
    await mongoose.connect(uri, {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useFindAndModify: false,
    })

    await DeprecateMe.findByIdAndUpdate(
        '000000000000000000000004',
        {
            hello: '',
        },
        {
            new: true,
        }
    )
}
run().then()

my package.json

    "mongoose": "^5.12.11",
    "mongodb-memory-server": "^6.9.6",
    "ts-node": "^10.0.0",
    "typescript": "^4.2.4"

Console

[nodemon] starting `ts-node src/index.ts`
(node:26540) [MONGODB DRIVER] DeprecationWarning: collection.findOneAndUpdate option [returnOriginal] is deprecate
d and will be removed in a later version.
(Use `node --trace-deprecation ...` to show where the warning was created)

Hope this helps, thanks for the awesome work :) lemme know if need more help

note
Model.findByIdAndUpdate options.returnOriginal = undefined | false | true all show this warning

@IslandRhythms IslandRhythms added typescript Types or Types-test related issue / Pull Request and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels May 26, 2021
@silentjohnny
Copy link

The deprecation was introduced in the latest MongoDB driver:

"Currently, the driver supports the option returnOriginal for findOneAndUpdate, instead of the returnDocument option outlined in the CRUD spec. We should add support for returnDocument, and deprecate the returnOriginal flag."

see https://jira.mongodb.org/browse/NODE-1812

@IslandRhythms
Copy link
Collaborator

IslandRhythms commented May 26, 2021

Ok so a couple things,

  1. only able to repro on 5.12.11
  2. We will be pathcing shortly
import { Schema, model, connect } from 'mongoose'

const deprecateMe = new Schema({
    hello: Schema.Types.String,
})

const DeprecateMe = model('yolo', deprecateMe)

const run = async () => {
    await connect("mongodb://localhost:27017", {
        useCreateIndex: true,
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useFindAndModify: false,
      });
    const entry = await DeprecateMe.create({hello: 'World'});
    console.log(entry);
    const test = await DeprecateMe.findByIdAndUpdate(
        {_id: entry.id},
        {
            hello: '',
        },
        {
            new: true,
        }
    )
    console.log(test);
}
run().then()

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label May 26, 2021
vkarpov15 added a commit that referenced this issue May 26, 2021
fixed deprecation warning for collection.findOneAndUpdate
@fabraga
Copy link

fabraga commented May 27, 2021

returnDocument

Can you teach us how to fix it in the node_modules while we wait for the updates?

@Roger-Heathcote
Copy link

I am getting this all of a sudden even though I've never used the "new" option or "returnOriginal". I use findOneAndUpdate in a number of places without problem. The single instance that is triggering this warning is this...

	await this.findOneAndUpdate(
		{ownerId, listId},
		{$push: {ordering: mongoose.Types.ObjectId(itemId)}},
		{upsert: true}
	)

It also happens if I remove the third parameter entirely. FYI I have {useFindAndModify: false} set in my connection string. I tried reverting to 5.12.10 and the problem disappeared.

@vkarpov15
Copy link
Collaborator

@Roger-Heathcote please make sure you've upgraded to the latest version of Mongoose (v5.12.13 as of this writing). If you're still experiencing this issue, please open a new issue and follow the issue template.

@Automattic Automattic locked as resolved and limited conversation to collaborators Jun 4, 2021
@vkarpov15 vkarpov15 removed the typescript Types or Types-test related issue / Pull Request label Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants