我有一个很大的数据库,有各种不一致的地方。我想澄清的一件事是根据人口改变国家地位。
{ "_id" : "D", "name" : "Deutschland", "pop" : 70000000, "country" : "Large Western" }
{ "_id" : "E", "name" : "Eire", "pop" : 4500000, "country" : "Small Western" }
{ "_id" : "G", "name" : "Greenland", "pop" : 30000, "country" : "Dependency" }
{ "_id" : "M", "name" : "Mauritius", "pop" : 1200000, "country" : "Small island"}
{ "_id" : "L", "name" : "Luxembourg", "pop" : 500000, "country" : "Small Principality" }
很明显,我想根据人口规模,改变农村地区的格局。
我尝试过这种方法,但很明显,我错过了一些与国家领域的最新情况相关的方法。
db.country.updateMany( { case : { $lt : ["$pop" : 20000000] }, then : "Small country" }, { case : { $gte : ["$pop" : 20000000] }, then : "Large country" }
编辑:在我写完之前发的。
我想用
$cond
这是可能的,还是有解决办法?