【问题标题】:Compare the field values in MongoDB比较 MongoDB 中的字段值
【发布时间】:2012-05-18 12:47:14
【问题描述】:

我有两个集合 A 和 B 对于 A 包含

{
  "_id" : ObjectId("4fb2143af31dfd122ce39c4b"),
  "Name" : "Freelander 2.2D",
  "Manufacture" : "Landrover"
}

和乙,

{
  "_id" : ObjectId("4fb21439f31dfd122ce39c4a")      
  "Name" : "Rangerover",
  "Manufacture" :  "Landrover",

}

让我知道如何检查 C# 驱动程序中 A 和 B 的字段值是否相同(这里是“名称”具有不同的值)。如果发现差异,我也需要更新

请多多指教,先谢谢了

【问题讨论】:

    标签: c# mongodb indexing


    【解决方案1】:

    您不能执行涉及多个集合的查询。一个查询 - 一个集合,周期。

    【讨论】:

      【解决方案2】:

      嗯,Sergio 基本上是对的(我看不到使用语言驱动程序的方法),但可以使用 shell:

      var a_in_b = function(o){ 
         var numB = db.B.find({Name:o.Name}).count();
         if (numB > 0) print (o.Name + " is in both A and B");
      } 
      
      > db.A.find()
      { "_id" : ObjectId("4fb2143af31dfd122ce39c4b"), "Name" : "Freelander 2.2D", "Manufacture" : "Landrover" }
      > db.B.find()
      { "_id" : ObjectId("4fb667d60569d84fec6ef57e"), "Name" : "Rangerover", "Manufacture" : "Landrover" }
      { "_id" : ObjectId("4fb66a830569d84fec6ef57f"), "Name" : "Freelander 2.2D", "Manufacture" : "Landrover" }
      > db.A.find().forEach(a_in_b);
      Freelander 2.2D is in both A and B
      

      如果您的要求是与管理员相关的,那么这可能就是您正在寻找的。如果您想从 C# 驱动程序执行此操作(我猜想像 SQL 连接),那么不,您不能。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-22
        • 1970-01-01
        • 1970-01-01
        • 2013-08-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多