Skip to content

Instantly share code, notes, and snippets.

@shipcake
Created July 19, 2019 13:12
Show Gist options
  • Save shipcake/c5e2221a25c9032f04c2931435aa0fcc to your computer and use it in GitHub Desktop.
Save shipcake/c5e2221a25c9032f04c2931435aa0fcc to your computer and use it in GitHub Desktop.
how to pull all object in array by data._id condition?
//find property_type in products to delete them.
const findallid = await products.findOne({ "storeuid": ctx.token.storeuid}).lean()
const MapId = await R.map(findallid.data,i=>{
return i._id
})
console.log(MapId) <--- return like [id1,id2...]
const remove = await products.findOneAndUpdate(
{ "storeuid": ctx.token.storeuid },
{
$pull:{"data.$[dataid].property_type":{subtypeid:iddel}}
},
{
arrayFilters:[{[`dataid._id`]:{$each:MapId}}]
}
)
return {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment