I have a documents in MongoDB, one of them looks like this:
{
"_id" : 100,
"name" : "Something",
"items" : [
{
"item" : 47,
"color" : "red"
},
{
"item" : 44,
"color" : "green"
},
{
"item" : 39,
"color" : "blue"
}
]
}
In every document I need to find the minimum item and delete it. So it should be like this:
{
"_id" : 100,
"name" : "Something",
"items" : [
{
"item" : 47,
"color" : "red"
},
{
"item" : 44,
"color" : "green"
}
]
}
It looks like findAndModify
function should be used here but I can't go any further.
How to find the minimum element in array and delete it?
I'm using MongoDB and Pymongo driver.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…