mongodb和关系数据库不一样,不可以直接使用"...Where 字段A=字段B"的方式来查找字段相同的条目。不过我们可以间接的实现,使用“$where”。No code you say a JB,废话不多说,直接贴代码:

db.foo.find({"$where":function(){
 for(var current in this){
   for(var other in this){
     if(current != other && this[current] == this[other]){
       return true;
     }
   }
 }
 return false;
}})

转载于:https://my.oschina.net/waterbear/blog/149847

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐