MongodB deleteOne not resolved?


#1

deleteOne not resolved?

Mac OSX

Meteor 1.3.2.4

db.collections.deleteOne

#2

Are you using a special collections package? Because this method doesn’t exists according to the current docs?


#3

Hi Stephan

https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/#db.collection.deleteOne


#4

try with rawCollection


#5

Hi Marc

Why do I need rawCollection? Thanks


#6

In Meteor, whenever you invoke a collection method (like myCollection.find()) you are actually using minimongo. On the server, minimongo eventually accesses the “real” Mongo database, but it does not support all MongoDB functionality.

Fortunately, Meteor also lets you access the underlying npm module code if you want to do more than minimongo allows. In order to use this functionality you make use of the rawCollection method, which gives you a reference to the npm module’s collection object.

By using this object you get full access to all that goodness (including deleteOne). Unfortunately, these “raw” methods are asynchronous and so need to be wrapped into sync-style methods compatible with Meteor’s other server-side methods. You may wrap in Promises* or Fibers/Futures. The easiest to understand if you’re used to Meteor’s traditional sync-style is wrapping in a Fiber/Future with Meteor.wrapAsync:

const rawCollection = myCollection.rawCollection();
const deleteOne = Meteor.wrapAsync(rawCollection.deleteOne, rawCollection);
// now you can use deleteOne using the signature in the npm module, but without the callback:
deleteOne(filter, options);

You can also adapt this technique to extend the Meteor’s minimongo collection object with the wrapped method(s) you need. Then you can use them in a more natural Meteor way.

The important point to remember is that you only have access to these raw methods on the server.

*Edit: The 2.2 API automatically returns a Promise if no callback is given. This means that if you want to write a Promise chain, or use async/await it’s now quite easy.


Why i can't use the $lookup operator in meteor 1.4?
#7

Hi Rob

Does it also mean that multiple upsert by a single command can only be done with rawCollections?

var Collections = {};
FutureTasks = Collections.FutureTasks = new Mongo.Collection('future_tasks');
const rawSparkAPICollection = FutureTasks.rawCollection();
const deleteOne = Meteor.wrapAsync(rawSparkAPICollection.deleteOne, rawSparkAPICollection);

says deleteOne unresolved?


#8

Hmm - it’s definitely there for me. Where are you seeing deleteOne unresolved?


#9

lib/collections.js

var Schemas = {};

Schemas.FutureTask = new SimpleSchema({
    number: {
        type: String,
        label: "TICKET_NUMBER",
        max: 10,  
        index: true,
        unique: true,
        optional: true
    },
    userid: {
        type: String,
        label: "USER_ID",
        max: 20,
        optional: true
    },
    assigned_to: {
        type: String,
        label: "ASSIGNED_TO",
        max: 50,
        optional: true
     },
start_date: {
        type: String,  
        label: "START_DATE",
        max: 20,
        optional: true
      },
    end_date: {
        type: String,
        label: "END_DATE",
        max: 20,
        optional: true
      },
    count: {
        type: Number,
        label: "COUNT",
        optional:true
    }

});

var Collections = {};

FutureTasks = Collections.FutureTasks = new Mongo.Collection('future_tasks');
const rawSparkAPICollection = FutureTasks.rawCollection();

/* deleteOne unresolved below ? */

  const deleteOne = Meteor.wrapAsync(rawSparkAPICollection.deleteOne, rawSparkAPICollection);
  FutureTasks.attachSchema(Schemas.FutureTask);

Is not using rawCollection also the reason why I cannot do multi upsert?