Py学习  »  MongoDB

MongoDB带条件的updateMany

Clauric • 4 年前 • 963 次点击  

我有一个很大的数据库,有各种不一致的地方。我想澄清的一件事是根据人口改变国家地位。

{ "_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

这是可能的,还是有解决办法?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54014
 
963 次点击  
文章 [ 1 ]  |  最新文章 4 年前