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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -