我的MongoRegex遇到了一些问题,查询如下:
db.part_instances.find({
'Part.name' : /Bauteilname/i,
'Part.version' : /1/i,
'LocationInstanceLinks' : {'$in' : [1001]},
'Part.Manufacturer.name':/Hersteller/i
});
返回的数据如下: 正如您将注意到的,4个结果中只有一个应该匹配,或者我做错了什么?
[
{
"_id": 1211,
"Category": {
"name": "",
"id": "",
"building_id": 1001
},
"Craft": {
"name": "",
"id": "",
"building_id": 1001
},
"LocationInstanceLinks": [
1001
],
"MaintenanceTypeLinks": [],
"Part": {
"name": "Bauteilname1",
"id": 1203,
"sort_name": "bauteilname1",
"sort_manufacturer": "hersteller2",
"version": "1",
"buildyear": "",
"status": "local_object",
"Manufacturer": {
"name": "Hersteller2",
"id": "1202"
},
"Building": {
"id": 1001,
"name": "Gebäude_dl1.admin",
"location_instance_id": 1001
}
},
"article_number": "",
"comments": "",
"deleted": 1,
"deleted_date": "Thu, 08 Sep 2011 09:57:22 +0200",
"ean_number": "",
"following_product": "",
"implementation_date": "08.09.2011",
"in_room_position": "",
"manufacturer_number": ""
},
{
"_id": 1212,
"Category": {
"name": "",
"id": "",
"building_id": 1001
},
"Craft": {
"name": "",
"id": "",
"building_id": 1001
},
"LocationInstanceLinks": [
1001
],
"MaintenanceTypeLinks": [],
"Part": {
"name": "Bauteilname",
"id": 1201,
"sort_name": "bauteilname",
"sort_manufacturer": "hersteller",
"version": "1",
"buildyear": "",
"status": "local_object",
"Manufacturer": {
"name": "Hersteller",
"id": "1201"
},
"Building": {
"id": 1001,
"name": "Gebäude_dl1.admin",
"location_instance_id": 1001
}
},
"article_number": "",
"comments": "",
"deleted": 0,
"deleted_date": "Thu, 08 Sep 2011 10:07:36 +0200",
"ean_number": "",
"following_product": "",
"implementation_date": "",
"in_room_position": "",
"manufacturer_number": ""
},
{
"_id": 1214,
"Category": {
"name": "",
"id": "",
"building_id": 1001
},
"Craft": {
"name": "",
"id": "",
"building_id": 1001
},
"LocationInstanceLinks": [
1001
],
"MaintenanceTypeLinks": [],
"Part": {
"name": "Bauteilname_Fenster",
"version": "1",
"buildyear": "",
"status": "local_object",
"sort_name": "bauteilname_fenster",
"sort_manufacturer": "hersteller_fenster",
"Manufacturer": {
"name": "Hersteller_Fenster",
"id": 1204
},
"Building": {
"location_instance_id": 1001,
"name": "Gebäude_dl1.admin",
"id": 1001
},
"id": 1206
},
"ServicecartLinks": [],
"article_number": "",
"comments": "",
"deleted": 1,
"deleted_date": "Thu, 08 Sep 2011 10:07:36 +0200",
"ean_number": "",
"following_product": "",
"implementation_date": "08.09.2011",
"in_room_position": "",
"manufacturer_number": "",
"parents": []
},
{
"_id": 1213,
"Category": {
"name": "",
"id": "",
"building_id": 1001
},
"Craft": {
"name": "",
"id": "",
"building_id": 1001
},
"LocationInstanceLinks": [
1001
],
"MaintenanceTypeLinks": [],
"Part": {
"Building": {
"location_instance_id": 1001,
"name": "Gebäude_dl1.admin",
"id": 1001
},
"Manufacturer": {
"name": "Hersteller_Glas",
"id": "1203"
},
"buildyear": "",
"name": "Bauteilname_Glas",
"sort_manufacturer": "hersteller_glas",
"sort_name": "bauteilname_glas",
"status": "local_object",
"version": "1",
"id": 1205
},
"ServicecartLinks": [],
"article_number": "",
"comments": "",
"deleted": 1,
"deleted_date": "Thu, 08 Sep 2011 10:07:36 +0200",
"ean_number": "",
"following_product": "",
"implementation_date": "08.09.2011",
"in_room_position": "",
"manufacturer_number": ""
},
{
"_id": 1215,
"Category": {
"name": "",
"id": "",
"building_id": 1001
},
"Craft": {
"name": "",
"id": "",
"building_id": 1001
},
"LocationInstanceLinks": [
1001
],
"MaintenanceTypeLinks": [],
"Part": {
"name": "Bauteilname2",
"id": 1207,
"sort_name": "bauteilname2",
"sort_manufacturer": "hersteller2",
"version": "1",
"buildyear": "",
"status": "local_object",
"Manufacturer": {
"name": "Hersteller2",
"id": 1202
},
"Building": {
"id": 1001,
"name": "Gebäude_dl1.admin",
"location_instance_id": 1001
}
},
"article_number": "",
"comments": "",
"deleted": 1,
"deleted_date": "Thu, 08 Sep 2011 10:07:36 +0200",
"ean_number": "",
"following_product": "",
"implementation_date": "08.09.2011",
"in_room_position": "",
"manufacturer_number": ""
},
{
"_id": 1216,
"Category": {
"name": "",
"id": "",
"building_id": 1001
},
"Craft": {
"name": "",
"id": "",
"building_id": 1001
},
"LocationInstanceLinks": [
1001
],
"MaintenanceTypeLinks": [],
"Part": {
"name": "Bauteilname_Fenster",
"id": 1206,
"sort_name": "bauteilname_fenster",
"sort_manufacturer": "hersteller_fenster",
"version": "1",
"buildyear": "",
"status": "local_object",
"Manufacturer": {
"name": "Hersteller_Fenster",
"id": 1204
},
"Building": {
"id": 1001,
"name": "Gebäude_dl1.admin",
"location_instance_id": 1001
}
},
"PartInstanceLinks": [],
"article_number": "",
"comments": "",
"ean_number": "",
"following_product": "",
"implementation_date": "08.09.2011",
"in_room_position": "",
"manufacturer_number": ""
},
{
"_id": 1217,
"Category": {
"name": "",
"id": "",
"building_id": 1001
},
"Craft": {
"name": "",
"id": "",
"building_id": 1001
},
"LocationInstanceLinks": [
1001
],
"MaintenanceTypeLinks": [],
"Part": {
"name": "Bauteilname_Glas",
"id": 1205,
"sort_name": "bauteilname_glas",
"sort_manufacturer": "hersteller_glas",
"version": "1",
"buildyear": "",
"status": "local_object",
"Manufacturer": {
"name": "Hersteller_Glas",
"id": "1203"
},
"Building": {
"id": 1001,
"name": "Gebäude_dl1.admin",
"location_instance_id": 1001
}
},
"PartInstanceLinks": [],
"article_number": "",
"comments": "",
"ean_number": "",
"following_product": "",
"implementation_date": "08.09.2011",
"in_room_position": "",
"manufacturer_number": ""
}
]
答案 0 :(得分:1)
我不知道MongoRegex,但一般考虑正则表达式模式:
/Bauteilname/i
表示查找 任何 不区分大小写的单词实例。这意味着它将匹配:
同样适用于其他模式。您的所有模式看起来都与您列出的数据集中的所有字段相匹配。
尝试/^Bauteilname$/i
以匹配确切的字词。