MongoDB C# How to delete nested record -
i have following structure
{     "_id" : "68f77d83-7141-4867-a355-16eda3ebe470",     "roles" : [          {             "id" : "0001010260",             "roleids" : [                  "customer",                  "admin"             ]         }     ] }   now try delete 1 roleid "customer" or "admin". have 2 filters combine and.
filterdefinition<roleentry> subfilter = builders<roleentry>.filter.eq(p => p.sub, _sub); filterdefinition<roleentry> idfilter = builders<roleentry>.filter.elemmatch(p => p.roles, r => r.id == _role.id);   i can delete whole roleids element with. don't know how 1 level deeper.
tried
updatedefinition<roleentry> updatedefinition = builders<roleentry>.update.unset("roles.$.roleids"); updateresult result = await _roleentryconnector.roleentrycollection.updateoneasync(andfilter, updatedefinition, null, cancellationtoken);   but removed roleids completly.
wow yesterday tried hours , after posting question think got it.
updatedefinition<roleentry> updatedefinition = builders<roleentry>.update.pull("roles.$.roleids", "customer");      
Comments
Post a Comment