當我在列下方執行時,它會在添加列時給出結果,但是當我查詢表時,沒有顯示新列。
db.getCollection("arcm_qc").aggregate([
{
$addFields: {
MGE_ID: { $arrayElemAt: [{ "$split": ["$MCA Go", "-"] }, 0] }
}
}
])
uj5u.com熱心網友回復:
您不能僅使用聚合在集合中添加欄位。但是您可以在更新查詢中使用聚合,如下所示:
db.collection.update({/*the documents you want to update or empty to update all*/},
[
{
$addFields: {
MGE_ID: {
$arrayElemAt: [{"$split": ["$MCA Go","-"]},0]
}
}
}
],
{
multi: true
})
示例在這里
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/359643.html
下一篇:MongoDB查詢條件計數
