0

I'm using the MongoDB Bulk API to do document upserts for objects stored in an array. My code looks something like this:

   mongoClient.connect(this.uri, function(err, db) {
        if(err) console.error(err);

        var bulk=db.collection(tableName).initializeUnorderedBulkOp();

        array.forEach(function (item) {
            var query= {id: item.id};

            bulk.find(query).upsert().update(item, function(err, res) {
                if(err) console.error("Error inserting item\n",err);

            });
        });

        bulk.execute(function(err, res) {
            //updates finished so close database
            db.close();
            //log the BulkWriteResult
            console.log(res);
        });             
    });

However, when I print out the BulkWriteResults in the execute function callback, the terminal prints out this text:

BulkWriteResult {
   ok: [Getter],
   nInserted: [Getter],
   nUpserted: [Getter],
   nMatched: [Getter],
   nModified: [Getter],
   nRemoved: [Getter],
   getInsertedIds: [Function],
   getUpsertedIds: [Function],
   getUpsertedIdAt: [Function],
   getRawResponse: [Function],
   hasWriteErrors: [Function],
   getWriteErrorCount: [Function],
   getWriteErrorAt: [Function],
   getWriteErrors: [Function],
   getLastOp: [Function],
   getWriteConcernError: [Function],
   toJSON: [Function],
   toString: [Function],
   isOk: [Function] }

Why doesn't it display the actual numbers of documents inserted, upserted, etc.?

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
deepmindz
  • 598
  • 1
  • 6
  • 14

0 Answers0