mongoose: useFindAndModify: true - wrong error message
Do you want to request a feature or report a bug? bug
What is the current behavior?
node test.js
(node:36160) DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.
All Assertions Pass.
If the current behavior is a bug, please provide the steps to reproduce.
#!/usr/bin/env node
"use strict";
const assert = require("assert");
const mongoose = require("mongoose");
mongoose.set("useFindAndModify", true);
const {Schema, connection} = mongoose;
const DB = "6880";
const URI = `mongodb://localhost:27017/${DB}`;
const OPTS = {family: 4, useNewUrlParser: true};
const schema = new Schema({
name: String,
});
const Test = mongoose.model("test", schema);
const test = new Test({name: "test1"});
async function run() {
await mongoose.connect(URI, OPTS);
await connection.dropDatabase();
const doc = await Test.create(test);
assert.ok(doc);
const cond = {};
const update = {name: "test2"};
const options = {new: true};
const updated = await Test.findOneAndUpdate(cond, update, options); // <- here
assert.strictEqual(updated.name, "test2");
console.log("All Assertions Pass.");
await connection.close();
}
run();
What is the expected behavior? should print nothing I guess
because it offers to replace findOneAndUpdate with findOneAndUpdate which makes no sense to me
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version. node: 8.15.1 mongodb 4.0.6 mongoose: 5.4.16 / 5.4.20
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (7 by maintainers)
Commits related to this issue
- fix: add findAndModify deprecation warning that references the useFindAndModify option Re: #7644 — committed to Automattic/mongoose by vkarpov15 5 years ago
- fix(query): dont show useFindAndModify deprecation warning if useFindAndModify = false Re: #7644 — committed to Automattic/mongoose by vkarpov15 5 years ago
it was good time when I was working closely with mongoose 3 years ago. I have created lots of issues about
populatefunctinality and even made some PR’s. things has changed since that time. whoever hired you to read and answer issues, has made this project looks like corporate shit, where the end user can do nothing because he meets a wall of text, which basically says “fuck off”. fuck off you too.You are setting “useFindAndModify” to true. As the message tells you, this is deprecated. Set it to false and the message should disappear i guess?
Edit: More about this here: https://mongoosejs.com/docs/deprecations.html#-findandmodify-