Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Update mongodb driver to v3 #268

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

Update mongodb driver to v3 #268

gustawdaniel opened this issue Feb 15, 2018 · 7 comments

Comments

@gustawdaniel
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

@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
Copy link

The driver has been updated in Meteor 1.7.

@lamalex
Copy link

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
Copy link

mitar commented Sep 3, 2018

There is no third argument to update in Meteor.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants