MongoDB –大文字への更新
ドキュメント。すべての「ソース」値を大文字に更新します。
whois.json
{
"_id" : NumberLong(1),
"country" : "au",
"source" : "apnic"
}
{
"_id" : NumberLong(2),
"country" : "cn",
"source" : "apnic"
}
{
"_id" : NumberLong(3),
"country" : "us",
"source" : "arin"
}
溶液
準備ができている関数があるかどうかはわかりませんが、値を大文字に更新するスクリプトを作成できます。
db.whois.find({ "source": { "$exists": true } }).forEach(function(doc) {
db.whois.update(
{ "_id": doc._id },
{ "$set": { "source": doc.source.toUpperCase() } }
);
});
出力
whois.json
{
"_id" : NumberLong(1),
"country" : "au",
"source" : "APNIC",
}
{
"_id" : NumberLong(2),
"country" : "cn",
"source" : "APNIC",
}
{
"_id" : NumberLong(3),
"country" : "us",
"source" : "ARIN",
}
完了しました。