How to get the _id of the last added document?


I want to add a product in my Product database and open the product for sell after a certain time. Thus i’m using synced-cron package to update an attribute of the document to be published to the client.

      name: productName,
      price: 0,
      winner: "Something",
      time: time,
      started: false
        name: 'sample Scheduled job for a product',
        schedule: function(parser) {
            return   parser.cron(bidStartTime);

        job: function() {
            ProductList.update( {name: productName},
                {$set :{ started:true} });

Few things to note here is that I want the synced-cron job name should contain the id of the added documents.Otherwise the cron job won’t be added , it’ll just overwrite the existing one. how do I get the Mongodb _id of this added document so that i can incorporate it with the cron job name.


ProductList.insert(...) returns the _id of the inserted document :wink:


in other words do

var latestId = ProductList.insert({ ...