Reputation: 1175
So I am using a method is suggesting, but giving me a warning not to use it, suggesting the same method. What?
// Upgrade stats query
if (args.type === "stats") {
const user = await User.findById(args.id, (err, res) => {
if (err) console.log(err);
}).then(user => {
return user;
});
if ((await user.meta.statpoints) > 1) {
let query;
User.findOneAndUpdate(
{ _id: args.id },
{
$inc: {
"meta.currency.cs": 1
}
},
(err, user) => {
if (err) console.log(err);
}
).then(user => {
//console.log(user.meta.currency);
});
}
}
It is giving me this warning:
(node:1360) DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.
I mean its not a huge deal, but it is kind of weird it is doing it.
Upvotes: 2
Views: 176
Reputation: 54
useFindAndModify is true by default, so you can set it to false globally
mongoose.set('useFindAndModify', false);
or with connection
mongoose.connect(uri, { useFindAndModify: false });
Upvotes: 1