1

I try to perform bulk update operation using Official Mongo c# 2.0 driver via the following code :

 var query = 
 Builders<Profile>.Filter.In(p => p.userId, listBounce.Values.ToList()) &
 Builders<Profile>.Filter.In(p => p.ID,  listBounce.Keys.Select(x=> new ObjectId(x)).
 ToList());

 var update = Builders<Profile>.Update.Set(p => p.MailLists[-1].Status, (int)wrongEmailStatusAssetId);

 dbCollection.UpdateManyAsync(query, update).Wait();

But there is the following error has been occurred

{"A write operation resulted in an error.\r\n  
The positional operator did not find the match needed from the query.   
Unexpanded update: p2l.$.status"}

I need to update each element's property in array which matches the query. The documents structure is :

{
    "_id" : ObjectId("55eeb5da965bb036984110b9"),
    "created" : ISODate("2015-09-08T10:17:59.784Z"),
    "userId" : 13929,
    "email" : "go-get@yandex.ru",
    "firstName" : "Skrillex",
    "lastName" : "Skrillex",
    "phoneNumber" : "",
    "isUnsubscribed" : false,
    "isAboveLimit" : false,
    "status" : 0,
    "userAgent" : 9760,
    "isDeleted" : false,
    "p2l" : [ 
        {
            "listId" : 45165,
            "status" : 131,
            "subscriptionDate" : ISODate("2015-09-04T06:24:55.763Z")
        }
    ]
}
Vladyslav Furdak
  • 1,765
  • 2
  • 22
  • 46
  • Yet another gregarious overuse of lambda operations. Can you please try to show an actual document you expect to match. The basic problem is that your "query" portion never attempts to "match" an array element than can be passed to the positional `$` operator within the "update" as is implemented. Noting that is "clear as mud" from all the unnecessary lambda garbage in here. Someone at MSDN should be shot. – Blakes Seven Sep 08 '15 at 13:39
  • `db.profiles.update( { "userId" : { "$in" : [13929] }, "_id" : { "$in" : [ObjectId("55eeb5da965bb036984110b9")]}}, { $set : { "p2l.$.status" : 131 } } )` Why that code doesn't work ? – Vladyslav Furdak Sep 08 '15 at 14:30

1 Answers1

0

Just add Builders<Profile>.Filter.Exists(p=>p.MailLists) to query and the issue could be solved.

Vladyslav Furdak
  • 1,765
  • 2
  • 22
  • 46