2

I try to call collection.bulkWrite() in MongoDB stitch functions, but I get an error - “bulkWrite is not a function”. Is it possible to use bulkWrite() in MongoDB stitch functions?

Here is my stitch function - and I made it “run as a system”:

exports = function(arg){
  var collection = context.services.get("mongodb-atlas").db("testDATABASE").collection("allSkuTable");
  return collection.bulkWrite(some_paramets_inside);
};

What is the proper way to call bulkWrite() if it is even possible?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 2
    You mean from the browser SDK I presume? Then No, but also Yes. There is actually a whole page of [Limitations](https://docs.mongodb.com/stitch/mongodb/mongodb-service-limitations/#bulk-write-operations) with the specifics of "bulk operations" highlighted in that link. However as noted you can create [System Functions](https://docs.mongodb.com/stitch/functions/#system-functions), and these actually have access to the "Full API". – Neil Lunn Mar 26 '19 at 08:34
  • Thank you for answering. I know about limitations. But I don’t understand - can I use bulkWrite() or just - insertOne() – Sergei Vakhnin Mar 26 '19 at 11:06
  • 1
    The meaning of "full access" in the case of System Functions has to do with bypassing the [Rules and Roles](https://docs.mongodb.com/stitch/mongodb/define-roles-and-permissions/index.html) for your Stitch app. Unfortunately, collection.bulkWrite() is not currently supported even in Stitch Functions run as the system user. – Chris Bush Mar 26 '19 at 14:12

0 Answers0