Skip to content

Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead. #616

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

Closed
akat1978 opened this issue Feb 9, 2021 · 24 comments

Comments

@akat1978
Copy link

akat1978 commented Feb 9, 2021

Since yesterday without any change on package.json or code change i am getting an error at console per request.

Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.

Any ideas?

I am using latest mongoDB version (4.4.3) container image

mongo datasource

 const config = {
      name: 'mongodb',
      connector: 'mongodb',
      host: '0.0.0.0',
      port: 27017,
      user: 'user',
      password: 'xxxxx',
      database: 'database',
      useNewUrlParser: true,
};

Please advice!

@wilywork
Copy link

wilywork commented Feb 9, 2021

I'm getting the same error too, I use:

loopback 3.27.0,
MongoDB 4.0.4,
nodeJS 8.12.0,
loopback-connector-mongodb 5.2.2.

I didn't do any version updates, everything worked perfectly and now this message is floating around. On my local computer this message does not appear, only in Amazon's ElastichBean.

@nodesocket
Copy link

nodesocket commented Feb 10, 2021

I believe this is just staying that use of j should be updated to use writeConcern: {}.

For example. This

let mongodbClient = new MongoClient({
    useUnifiedTopology: true,
    useNewUrlParser: true,
    connectTimeoutMS: 10000,
    poolSize: 10,
    j: true
});

Should be update to this:

let mongodbClient = new MongoClient({
    useUnifiedTopology: true,
    useNewUrlParser: true,
    connectTimeoutMS: 10000,
    poolSize: 10,
    writeConcern: {
        j: true
    }
});

See the following MongoDB Node.js documentation on WriteConcern

@akat1978
Copy link
Author

akat1978 commented Feb 10, 2021

I believe this is just staying that use of j should be updated to use writeConcern: {}.

For example. This

let mongodbClient = new MongoClient({
    useUnifiedTopology: true,
    useNewUrlParser: true,
    connectTimeoutMS: 10000,
    poolSize: 10,
    j: true
});

Should be update to this:

let mongodbClient = new MongoClient({
    useUnifiedTopology: true,
    useNewUrlParser: true,
    connectTimeoutMS: 10000,
    poolSize: 10,
    writeConcern: {
        j: true
    }
});

See the following MongoDB Node.js documentation on WriteConcern

Nope, doesn't work i modify my datasource to this:

import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = {
    name: 'mongodb',
    connector: 'mongodb',
    host: '0.0.0.0',
    port: 27017,
    user: 'user',
    password: 'XXXXX',
    database: 'db_name',
    useNewUrlParser: true,
    useUnifiedTopology: true,
    writeConcern: {
        j: true,
    },
};

// Observe application's life cycle to disconnect the datasource when
// application is stopped. This allows the application to be shut down
// gracefully. The `stop()` method is inherited from `juggler.DataSource`.
// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html
@lifeCycleObserver('datasource')
export class MongodbDataSource
  extends juggler.DataSource
  implements LifeCycleObserver {
  static dataSourceName = 'mongodb';
  static readonly defaultConfig = config;

  constructor(
    @inject('datasources.config.mongodb', {optional: true})
    dsConfig: object = config,
  ) {
    super(dsConfig);
  }
}

I am still getting the same warning message "Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead."

@xardit
Copy link

xardit commented Feb 10, 2021

same here on my local machine

@folkmanis
Copy link

Same problem. I removed option { w: 0 } from insertOne operation and - no warning!
Setting option to {writeConcern: {w: 0}} as per documentation, results in TypeScript error.

native mongodb node.js driver v3.6.4
local mongodb v4.2.11

@akat1978
Copy link
Author

akat1978 commented Feb 10, 2021

Same problem. I removed option { w: 0 } from insertOne operation and - no warning!
Setting option to {writeConcern: {w: 0}} as per documentation, results in TypeScript error.

native mongodb node.js driver v3.6.4
local mongodb v4.2.11

The error is there from the beginning

> [email protected] start /Users/akat/flexcar/flexapp
> node -r source-map-support/register . "."

Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.
Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.
Server is running at http://[::1]:3000
Try http://[::1]:3000/ping

Then after each request GET, POST, PUT, PATCH is repeated, I change the configuration as you mentioned but nothing happens

@xardit
Copy link

xardit commented Feb 10, 2021

for me error on start is this:

Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.
Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.
(node:82031) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)

Probably something related to connector or juggler

@arbourd
Copy link

arbourd commented Feb 11, 2021

The deprecation warning is coming from the MongoDB driver. Was introduced in v3.6.4.

@valdepeace
Copy link

It is not an error it is a warning from node-mongodb-native. As @arbourd says is introduced in v3.6.4(https://github.com/mongodb/node-mongodb-native/blob/v3.6.4/lib/write_concern.js)

 * Construct a WriteConcern given an options object.
   *
   * @param {object} [options] The options object from which to extract the write concern.
   * @param {(number|string)} [options.w] **Deprecated** Use `options.writeConcern` instead
   * @param {number} [options.wtimeout] **Deprecated** Use `options.writeConcern` instead
   * @param {boolean} [options.j] **Deprecated** Use `options.writeConcern` instead
   * @param {boolean} [options.fsync] **Deprecated** Use `options.writeConcern` instead
   * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
   * @return {WriteConcern}
   */
  static fromOptions(options) {

If not use object writeConcern return:

console.warn(
     'Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.'
    );
    return new WriteConcern(
      options.w,
      options.wtimeout,
      options.j || options.journal,
      options.fsync
    );

and loopback-connector-mongodb not implemented is option in validOptionNames https://github.com/strongloop/loopback-connector-mongodb/blob/master/lib/mongodb.js:

 // See https://github.com/mongodb/node-mongodb-native/blob/3.0.0/lib/mongo_client.js#L37
    const validOptionNames = [
      'poolSize',
      'ssl',
      'sslValidate',
      'sslCA',
      'sslCert',
      'sslKey',
      'sslPass',
      'sslCRL',
      'autoReconnect',
      'noDelay',
      'keepAlive',
      'keepAliveInitialDelay',
      'connectTimeoutMS',
      'serverSelectionTimeoutMS',
      'family',
      'socketTimeoutMS',
      'reconnectTries',
      'reconnectInterval',
      'ha',
      'haInterval',
      'replicaSet',
      'secondaryAcceptableLatencyMS',
      'acceptableLatencyMS',
      'connectWithNoPrimary',
      'authSource',
      'w',
      'wtimeout',
      'j',
      'forceServerObjectId',
      'serializeFunctions',
      'ignoreUndefined',
      'raw',
      'bufferMaxEntries',
      'readPreference',
      'pkFactory',
      'promiseLibrary',
      'readConcern',
      'maxStalenessSeconds',
      'loggerLevel',
      'logger',
      'promoteValues',
      'promoteBuffers',
      'promoteLongs',
      'domainsEnabled',
      'checkServerIdentity',
      'validateOptions',
      'appname',
      'auth',
      'user',
      'password',
      'authMechanism',
      'compression',
      'fsync',
      'readPreferenceTags',
      'numberOfRetries',
      'auto_reconnect',
      'minSize',
      'useNewUrlParser',
      'useUnifiedTopology',
      // Ignored options
      'native_parser',
      // Legacy options
      'server',
      'replset',
      'replSet',
      'mongos',
      'db',
    ];

@nodesocket
Copy link

nodesocket commented Feb 13, 2021

@valdepeace I understand the warning is coming from the MongoDB Node.js driver, but updating my MongoClient() constructor to:

    writeConcern: {
        j: true
    }

Still get's me Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead logged. I don't see j: true used anywhere else.

@nodesocket
Copy link

I've created an official bug report on the Jira for the Node.js driver at https://jira.mongodb.org/browse/NODE-3114 if anybody wants to follow along or chime in.

@wolrajhti wolrajhti mentioned this issue Feb 14, 2021
5 tasks
@BoLaMN
Copy link

BoLaMN commented Feb 15, 2021

its definitely the db.collection call if you change

MongoDB.prototype.collection = function(modelName) {
  if (!this.db) {
    throw new Error(g.f('{{MongoDB}} connection is not established'));
  }
  const collectionName = this.collectionName(modelName);
  return this.db.collection(collectionName);
};

to include the writeConcern object

MongoDB.prototype.collection = function(modelName) {
  if (!this.db) {
    throw new Error(g.f('{{MongoDB}} connection is not established'));
  }
  const collectionName = this.collectionName(modelName);
  return this.db.collection(collectionName, { writeConcern: { w: null } });
};

it stops complaining would have todo the same with the ping function as it calls db.collection directly

@pitor
Copy link

pitor commented Feb 17, 2021

As a temporary hack before we get a proper fix, I have added the prototype function from previous comment to my server/datasources.local.js

It gets rid of most of the warnings.

let mongoConnector = require('loopback-connector-mongodb');
let MongoDB = mongoConnector.MongoDB;

MongoDB.prototype.collection = function(model) {
    if (!this.db) {
      throw new Error(g.f('{{MongoDB}} connection is not established'));
    }
    var collectionName = this.collectionName(model);
    return this.db.collection(collectionName, { writeConcern: { w: null } });
  };

@wolrajhti
Copy link
Contributor

I just submit a PR to node-mongodb-native driver to fix the merging of writeConcern mongodb/node-mongodb-native#2744 which stop warning outputs.

An other PR is related to our topic and will remove the warnings mongodb/node-mongodb-native/pull/2743

@RAI-shyam
Copy link

RAI-shyam commented Mar 8, 2021

@wolrajhti , curious I see the PRs merged, but I'm still seeing the issue on my end, did mongodb 3.6.4 get updated or will a new version needs to be released?

@wolrajhti
Copy link
Contributor

@RAI-shyam A fix has been done on the branch 3.6 of the mongodb driver, it will be available when they will released 3.6.5 (or 3.7). hopefully very soon 🤞

@ashwinsoni
Copy link

Updating the version to 5.5.0 worked for me. Thanks for contributing :)

"loopback-connector-mongodb": "^5.5.0"

@Adimvicky
Copy link

Updating the version to 5.5.0 worked for me. Thanks for contributing :)

"loopback-connector-mongodb": "^5.5.0"

Hey @ashwinsoni. My package.json shows i'm already using "v5.5.0" but i still get this warning.

@akkapur
Copy link

akkapur commented Apr 27, 2021

Updating to version 6.0.0 resolves this for me.

"loopback-connector-mongodb": "^6.0.0",

@Adimvicky
Copy link

Thanks @akkapur! Upgrading to version 6.0.0 resolves it for me as as well.

@ashwinsoni
Copy link

@Adimvicky Sorry about that, seems like the modules were not cleaned and rebuild after updating to 5.5.0 on your machine.
Screenshot 2021-05-02 at 12 03 14 AM
But I'm happy that 6.0.0 did worked for you :)

@chiholiu10
Copy link

try add this one useUnifiedTopology: true

@stale
Copy link

stale bot commented Jul 14, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 14, 2021
@stale
Copy link

stale bot commented Jul 28, 2021

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests