Updating the Mongo.Collection API

I’ve been digging around in the MongoDB Node Native Driver source code for a basic node server that I’m building and I noticed some interesting things. I realize that Meteor’s Mongo.Collection API is it’s own API, but at it’s core is the mongo node native driver.

What I found interesting was that collection.findOne, collection.insert, collection.update and collection.remove are all deprecated in the native driver. Instead of each of those, they give you a list of other methods you should use instead like collection.insertOne, collection.deleteMany or collection.updateMany.

While I find collection.findOne to be very useful and collection.insert to be slightly more convenient to type than collection.insertOne, I’m sure the team creating the database we are using has some good reasons for deprecating the old methods and adding these newer ones. Aside from the performance enhancements that they likely add, they could even help us write a little less code.

// Example:
const arr = [ ...someObjects ];

// Insert objects in an array like this
arr.forEach((obj) => {
  SomeCollection.insert(obj);
});

// or like this 
SomeCollection.insertMany(arr);

I know we can access these features from the raw collections, but I was just curious if MDG is going to deprecate their implementations of these collection methods and implement the newer ones since this is the way MongoDB is going. Anyone know if this is in the roadmap?

1 Like

Since it’s part of core and qualifies as general maintenance, it’s probably not not on the roadmap. But it’s also probably fairly low priority for the time being.

I’m of the same general mindset that this kind of maintenance should be making it’s way into core. Since it’s not, I put together a package called clinical:extended-api that’s been collecting a few odds-and-ends API extensions like Session.toggle(), Collection.drop() and Collection.init().

I’d be happy to include and manage .insertMany() and .deleteMany() along with the others. Or fork it and use as a template for a mongo-latest-api package. Whichever.