node.js - Mongodb update() with $unset/$pull not doing $pull -


i trying remove items array in document in mongodb:

doc1   items     item        id=1     item        id=2     item        id=3 doc2   items     item       id=4     item       id=5     item       id=6 

i use remove example item id=5:

(...) updateitems({'items.id': 5},    { $unset: { 'items.$': 1 }},    { $pull: {'items'    : null} }); (...) function updateitems(objmatch, objunset, objpull){   coremodels.getprofiletable(req).update(     objmatch,      objunset,     {multi: true}, function(err) {         coremodels.getprofiletable(req).update(                         objmatch,                          objpull,                         {multi: true}, function(err) {         console.log('completed'); }); (...)                        

the $unset works fine, $pull doesn't seem working. end result of operation empty (null) item 5.

any ideas why $pull not removing empty document?

many in advance.

your updatearray function takes 2 parameters, you're passing three. don't think you're sending { $pull: {'items' : null} } driver @ all.

added:

once nullify item 5, match document no longer matches . second time cal update, try replacing objmatch { }, should remove nulls.


Comments