我的 MongoDB 資料庫非常大(大約 1000 萬個專案使用 1000 MB 的磁盤空間),但它的檔案沒有基于標題的 slug。目前的檔案如下所示:
{
"_id": {
"$oid": "630f3c32c1a580642a9ff4a0"
},
"title": "This is a title",
"Post": "this is a post"
}
但我想要這樣
{
"_id": {
"$oid": "630f3c32c1a580642a9ff4a0"
},
"title": "This is a title",
"slug": "this-is-a-title",
"Post": "this is a post"
}
uj5u.com熱心網友回復:
您可以為此在更新管道中使用$replaceAll
和:$toLower
db.collection.update(
{},
[{$set: {
slug: {
$replaceAll: {
input: {$toLower: "$title"},
find: " ",
replacement: "-"
}
}
}}],
{multi: true}
)
看看它在操場上的例子是如何作業的
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/506433.html