Inline document enhancement

I have the following strucutre doc

{
    "_id" : "NmBYYasdsa",
    "objectId" : "asdsd"
    "text" : "test",
    ....
    "publishedAt" : ISODate("2015-05-28T15:31:51Z"),
    "updatedAt" : ISODate("2015-05-28T15:31:51Z"),
    "data" : {
        .....
        "likeCount" : 0,
        "replyCount" : 0
    }
}

      

This is used to keep my database in sync with the external API. To do this, I go through the API once a minute and do a bulk update, matching the object id to update my database.

The problem is that the subdocument is data

not updated on update, any ideas as to why?

My Bulk Printing Technique

Mongo.Collection.prototype.upsertBulk = function(matcher, documents, options) {
  if (_.isEmpty(documents)) { throw Error('Empty list of documents provided'); }
  options = options || {};

  var operations = documents.map(function(_document) {
    _document._id = Random.id();

    var operation = {
      updateOne: {
        filter: {},
        update: { $set: _document },
        upsert: true
      },
    };
    operation['updateOne']['filter'][matcher] = _document[matcher];

    return operation;
  });

  this.__mongoCollection(function(collection) {
    collection.bulkWrite(operations, options, function(error, result) {
      if (error) { throw error; }
      return result;
    });
  });
};

      

+3
mongodb


source to share


No one has answered this question yet

Check out similar questions:

603
Request for documents whose array size exceeds 1
459
When to use MongoDB or other document-oriented systems?
400
Find a document with an array that contains a specific value
305
How do I update / update a document in Mongoose?
eleven
"upsert" in an inline document
five
Mongodb upsert inline document
4
Compacting an inline document in yiimongodbsuite
2
MongoError: $ all requires an array
1
Enhanced and Embedded Documents in MongoEngine
1
The field name generated from the embedded document. I'm crazy?



All Articles
Loading...
X
Show
Funny
Dev
Pics