MongoDB查询提供了wierd&结果不正确

时间:2013-11-30 14:10:26

标签: mongodb

我正在使用MongoDB 2.0.2。

当我运行以下查询时,我得到1个文档。

 { 
 "value.Other.part" : { "$regex" : "/*\\QPart\\E/*" , "$options" : "i"} ,
 "value.Other.wtype" : { "$regex" : "/*\\QAAA\\E/*" , "$options" : "i"} ,
 "value.Other._name" : { "$regex" : "/*others/*" , "$options" : "i"} , 
 "value.Other.type" : { "$regex" : "/*\\QELECTRONICS\\E/*" , "$options" : "i"}
 }

退回的文档:

/* 0 */
{
  "_id" : ObjectId("529720a0c50fff688e143dfe"),
  "value" : {
    "Other" : {
      "_id" : ObjectId("529720a0c50fff688e143dfb"),
      "type" : "ELECTRONICS",
      "_name" : "others",
      "part" : "Part Number Third Set",
      "wtype" : "AAA"
    },
    "AType" : {
      "_id" : ObjectId("529720a0c50fff688e143dfc"),
      "compunit" : "BBB Unit"
    }
  }
}

但是当我运行这个查询时,我得到了2个文件。

{ 
 "value.Other.part" : { "$regex" : "/*\\QPart\\E/*" , "$options" : "i"} ,
 "value.Other.wtype" : { "$regex" : "/*\\QAAA\\E/*" , "$options" : "i"} ,
 "value.Other._name" : { "$regex" : "/*others/*" , "$options" : "i"} , 
 "value.AType.compunit" : { "$regex" : "/*\\QBBB Unit\\E/*" , "$options" : "i"} , 
 "value.Other.type" : { "$regex" : "/*\\QELECTRONICS\\E/*" , "$options" : "i"}
}

退回的文档:

/* 0 */
{
  "_id" : ObjectId("52947a75c50f75b6a5f86bc6"),
  "value" : {
    "Other" : {
      "_id" : ObjectId("52947a75c50f75b6a5f86bc3"),      
      "type" : "PRODUCT IDENTIFICATION",
      "_name" : "others",
      "part" : "Part Number Third Set",
      "wtype" : "AAA"
    },
    "AType" : {      
      "_id" : ObjectId("52947a75c50f75b6a5f86bc4"),
      "compunit" : "BBB Unit"
    }
  }
}

/* 1 */
{
  "_id" : ObjectId("529720a0c50fff688e143dfe"),
  "value" : {
    "Other" : {
      "_id" : ObjectId("529720a0c50fff688e143dfb"),
      "type" : "ELECTRONICS",
      "_name" : "others",
      "part" : "Part Number Third Set",
      "wtype" : "AAA"
    },
    "AType" : {
      "_id" : ObjectId("529720a0c50fff688e143dfc"),
      "compunit" : "BBB Unit"
    }
  }
}

一个文档不满足查询。

有人可以解释什么是错的吗?

1 个答案:

答案 0 :(得分:0)

问题是因为number of regex in the query。在2.1.0版之前,您似乎无法在查询中使用超过4个正则表达式。 MongoDB JIRA ticket