-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Deprecated collection methods from mongodb #6880
Comments
Same here. I also get "find option [fields] is deprecated and will be removed in a later version." |
Here's some other ones I got |
Related to #6165 and can be reproduced on CI test You can specify
Warning: Do not set this option to false in production without proper testingHowever, other deprecated methods like Note: However this compatibility definitely will break soon as they have been marked as deprecated since Hence, I suggest next major release of mongoose (6.x) deprecate MongoDB 3.0 support and adopt all new API. Furthermore, MongoDB 3.0 has reached End-of-life in February, 2018, half of a year ago. Any thoughts? |
So ... why is this happening? Is it necessary to wait until the next mongoose major release? |
@lpiVasquez it's because the document says mongoose 5.x support MongoDB Server 3.0. For now it’s safe to just use the new API because underlying API still handling this for us. However it won’t work once the underlying library change this behavior and we need to be very careful when upgrading the underlying library. What I mean is not ignoring the issue but dropping support for MongoDB Server 3.0 in the next release 5.3. At least don’t break in 5.2. Just my opinion though. |
@IpiVasquez if by,
you mean,
Mongodb has a plan in place to make the various driver APIs more consistent. This is documented here in the mongodb crud spec
If we stick to the semver spec, then anything that breaks the API should happen in a MAJOR release, like Looking back at the history of the native driver, I wouldn't expect them to remove these methods until v4 of the driver. In the meantime, I think most of the deprecation warnings I've seen so far can be mitigated in userland by not calling deprecated methods. I'm guessing most of these methods will be removed in mongoose I think the 2 main issues for us to deal with in mongoose sooner rather than later are substituting findOneAndUpdate in the native driver will call findAndModify for you internally ( without the deprecation warning ) when you're connected to a server pre 3.2, so 6880.js#!/usr/bin/env node
'use strict';
const mongoose = require('mongoose');
mongoose.set('useFindAndModify', false);
const url = 'mongodb://localhost:27017/test';
const opts = { useNewUrlParser: true };
mongoose.connect(url, opts);
const conn = mongoose.connection;
const Schema = mongoose.Schema;
const schema = new Schema({
name: String
});
const Test = mongoose.model('test', schema);
async function run() {
await conn.dropDatabase();
let admin = conn.db.admin();
let { version } = await admin.serverInfo();
console.log(`mongodb: ${version}`);
console.log(`mongoose: ${mongoose.version}`);
let cond = {};
let update = { name: 'Sarah' };
let opts = {
upsert: true,
new: true
};
let sarah = await Test.findOneAndUpdate(cond, update, opts);
console.log(sarah);
return conn.close();
}
run(); Output:
You can also demonstrate this with just the native driver like this: 6880_native.js#!/usr/bin/env node
'use strict';
const { MongoClient, Logger } = require('mongodb');
const uri = 'mongodb://localhost:27017/test';
const opts = {
useNewUrlParser: true
};
async function run() {
const client = new MongoClient(uri, opts);
await client.connect();
const db = client.db('gh-6881');
await db.dropDatabase().catch(handleError);
Logger.setLevel('debug');
let res = await db
.collection('tests')
.findOneAndUpdate({}, { $set: { name: 'michael' } }, { upsert: true })
.catch(handleError);
Logger.setLevel('error');
console.log(res);
let doc = await db
.collection('tests')
.findOne({})
.catch(handleError);
console.log(doc);
process.exit(0);
}
run();
function handleError(e) {
return console.error(e.message);
} truncated Output:
|
Same here. I got this warning on application start:
|
`useFindAndModify` default to false now Automattic#6880 and make overwrite option compatibile to fixes Automattic#6887
If you find deprecation warning annoying, as a temporary workaround, you can start node.js process in cli with |
with mine:
love package-lock.json more than ever... |
There are several workarounds to get around these deprecation warnings:
We'll add some docs to help people clean up these deprecation warnings, and make some internal changes so mongoose doesn't cause one of these deprecation warnings. |
I'd be in favour of this 👍 Does mongoose already have support for the new methods, |
+1 |
so like, right now we have to ignore those warnings? i mean i am trying to create api, where i need to get everything from db and whenever i call collection.find().then()....etc it gives me same warning. what can i do to replace that find() method? |
If you're just bothered by the warnings, you can probably disable deprecation notices in Node (see Fonger's comment above), or you can revert back to an older version of Mongoose. |
So what I need to do? |
Got this warning message from mongoose each time i run a find query. Going to ignore it till after the next update from the mongoose team. (node:15500) DeprecationWarning: collection.find option [fields] is deprecated and will be removed in a later version. |
The fix for the |
Thanks for writing this doc https://mongoosejs.com/docs/deprecations.html Re: mongoose.set('useFindAndModify', false); is that true? I'm using I assume the underlying mongo db driver functions being used by mongoose will be / should be updated at some point. |
+1 I am having same deprecation warning for using Model.findByIdAndUpdate(); I am using following verisions:
|
Any news on this ? |
@gianpaj yes @daniyalawan check out the docs here the 'useFindAndModify' option applies to you if you call @Sastidar what issue(s) are you having after upgrading to [email protected]? All deprecation warnings should be addressed in these docs |
@lineus @gianpaj yep the need for the useFindAndModify option will go away with Mongoose 6.0.0. No timeframe for when we will release Mongoose 6. |
Regarding the deprecation warning - Will mongoose be phasing out the ability to use the I'm basically asking if I change all of my |
|
@anks333 the following example works for me. Can you modify it to show 6880.js#!/usr/bin/env node
'use strict';
const assert = require('assert');
const mongoose = require('mongoose');
mongoose.set('useFindAndModify', false);
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);
assert.strictEqual(updated.name, 'test2');
console.log('All Assertions Pass.');
await connection.close();
}
run(); Output:
|
@LBWright we have no intention of dropping support for findByIdAndUpdate, we will just swap out the underlying findAndModify without breaking the API |
findAndModify() 는 deprecated 될 예정이나 findByIdAndUpdate() 같은 메소드에서 기본값으로 findAndModify 사용중이므로 옵션을 해제함 Automattic/mongoose#6880
(node:10767) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Model.findByIdAndUpdate() is issuing a deprecation warning for mongodb - which has deprecated collection.findAndModify. Mongodb suggests using findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.
collection.ensureIndex is also deprecated - mongodb suggests using createIndexes instead.
If the current behavior is a bug, please provide the steps to reproduce.
Using Model.findByIdAndUpdate / findOneAndUpdate to alter a document returns these deprecation warnings.
What is the expected behavior?
No deprecation warnings!
Please mention your node.js, mongoose and MongoDB version.
Node v10.8.0
mongodb v3.6.2
mongoose v5.2.9
The text was updated successfully, but these errors were encountered: