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

Update mongodb driver to v3 #268

Closed
gustawdaniel opened this Issue Feb 15, 2018 · 7 comments

Comments

Projects
None yet
7 participants
@gustawdaniel

gustawdaniel commented Feb 15, 2018

What could we do?

I propose to update mongodb: "2.2.33" to mongodb: "3.0.2" in packages/npm-mongo/package.js.

Why?

I wanted to use The filtered positional operator described in docs of mongodb on this page:

https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/

It works only for newest mongodb driver. Article about this in under link:

http://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-36-array-filters.html

In this article there is written:

Using array filters with Node.js requires versions >= 3.0.0 of the MongoDB Node.js driver or >= 5.0.0 of mongoose in addition to v3.6 of the MongoDB server. Earlier versions of the MongoDB (2.x) and mongoose (4.x) do not support array filters.

Overview of the suggested solution

Simple change of version is not enough. @hwillson described this problem in this closed pull request:

meteor/meteor#9670

I do not know details mentioned by him, but I am interested in any help.

@klaussner

This comment has been minimized.

Collaborator

klaussner commented Feb 15, 2018

Here's a summary of the required changes I found while going through the node-mongodb-native CHANGES_3.0.0.md document:

Connection

MongoClient.connect passes the client instead of a database object to the callback function. This means that the driver doesn't create a Db instance from the database URL (e.g., mongodb://localhost:3001/meteor) anymore, so we have to create the Db instance in the callback:

function (err, client) {
  // ...
  const db = client.db("meteor");
  
  if (db.server.config.isMasterDoc) {
  // ...

Of course, the database name isn't always meteor, so we have to either parse the URL ourselves or use the (undocumented) client.s.options.dbName property to get the database name.

Removed functions

  • Cursor.prototype.next must be used instead of Cursor.prototype.nextObject (here).
  • MongoClient.prototype.close must be used instead of Db.prototype.close (here).

Renamed option

@benan789

This comment has been minimized.

benan789 commented May 9, 2018

Using arrayFilters is working with rawCollection but not through meteor. Will this be added soon? I'm on 1.7-rc.3.

@dobesv

This comment has been minimized.

dobesv commented May 14, 2018

BTW I believe if you call client.db() with no parameter it'll use the dbName from the connection URL.

@klaussner

This comment has been minimized.

Collaborator

klaussner commented May 15, 2018

@dobesv This feature was added to node-mongodb-native shortly after I created the first pull request (meteor/meteor#9790). I changed the constructor to use client.db() in meteor/meteor#9831. 🙂

@klaussner

This comment has been minimized.

Collaborator

klaussner commented Jul 7, 2018

The driver has been updated in Meteor 1.7.

@lamalex

This comment has been minimized.

lamalex commented Sep 3, 2018

On Meteor 1.7.0.5 and

Journal.Totals.update(
    { $and: c.q },
    { $inc: { [identifier]: nutrient.value } },
    { arrayFilters: [ { 't.providerData.internalID': nutrient.providerData.internalID } ] }
);

fails whereas

Journal.Totals.rawCollection().update(
    { $and: c.q },
    { $inc: { [identifier]: nutrient.value } },
    { arrayFilters: [ { 't.providerData.internalID': nutrient.providerData.internalID } ] }
);

passes.

@mitar

This comment has been minimized.

Collaborator

mitar commented Sep 3, 2018

There is no third argument to update in Meteor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment