PHP中的MongoRegex返回错误的结果?

PHP中的MongoRegex返回错误的结果?,php,regex,mongodb,Php,Regex,Mongodb,我的MongoRegex遇到一些问题,查询如下: db.part_instances.find({ 'Part.name' : /Bauteilname/i, 'Part.version' : /1/i, 'LocationInstanceLinks' : {'$in' : [1001]}, 'Part.Manufacturer.name':/Hersteller/i }); 返回的数据如下所示: 你会注意到,4个结果中只有一个应该匹配,还是我做错了什么

我的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": ""
    }
]

我不知道MongoRegex,但考虑到一般的正则表达式模式:

/bauteinname/i
表示查找该单词的任何不区分大小写的实例。这意味着它将匹配:

  • 鲍泰尔名字
  • BauteinName_Fenster
  • 我的名字比你的名字好
其他模式也是如此。所有模式看起来都与列出的数据集中的所有字段相匹配

/^bauteinname$/i
一次尝试匹配确切的单词