无法在异常特定的查询上使用$in参数

2024-10-03 02:43:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用pythoneve从mongodb后端创建API。给定以下URL:

http://127.0.0.1:5000/api/metabolites/?where={"Adducts" : {"$elemMatch" : {"Polarity" : "Positive",  "Accurate Mass" : {"$lte" : 991.5, "$gte" : 991.48}}}}&projection={"Identification Information.Name" : 1, "Identification Information.Molecular Formula" : 1, "Adducts.Positive.$":1}&max_results=60}}

退回以下物品:

{
    "_items": [
        {
            "_updated": "Thu, 01 Jan 1970 00:00:00 GMT",
            "Adducts": [
                {
                    "Polarity": "Positive",
                    "Adduct": "[M+Na]1+",
                    "Accurate Mass": 991.4873,
                    "Isotopic Distribution": [
                        [
                            991.4873,
                            100
                        ],
                        [
                            992.49066,
                            52.99707
                        ],
                        [
                            993.49155,
                            3.90449
                        ]
                    ]
                }
            ],
            "_created": "Thu, 01 Jan 1970 00:00:00 GMT",
            "_id": "RMGKGCYVUJKQSS-UHFFFAOYSA-N",
            "_etag": "de40db1e4e8639183bc70eabf103ee10cbbd905c",
            "Identification Information": {
                "Name": "Goyasaponin III",
                "Molecular Formula": "C49H76O19"
            }
        },
        {
            "_updated": "Thu, 01 Jan 1970 00:00:00 GMT",
            "Adducts": [
                {
                    "Polarity": "Positive",
                    "Adduct": "[M+2Na]2+",
                    "Accurate Mass": 991.48328,
                    "Isotopic Distribution": [
                        [
                            991.48328,
                            100
                        ],
                        [
                            991.9818,
                            1.47744
                        ],
                        [
                            991.98496,
                            95.17841
                        ],
                        [
                            992.4854,
                            8.63097
                        ]
                    ]
                }
            ],
            "_created": "Thu, 01 Jan 1970 00:00:00 GMT",
            "_id": "GWXCWXJFJNAEPC-IRAMQKHQSA-N",
            "_etag": "fc11f8ba1b409693e97e3f60974dbd6443f54901",
            "Identification Information": {
                "Name": "Ganglioside GT2 (d18:1/16:0)",
                "Molecular Formula": "C88H152N4O42"
            }
        },
        {
            "_updated": "Thu, 01 Jan 1970 00:00:00 GMT",
            "Adducts": [
                {
                    "Polarity": "Positive",
                    "Adduct": "[M+2Na-H]1+",
                    "Accurate Mass": 991.48954,
                    "Isotopic Distribution": [
                        [
                            991.48954,
                            100
                        ],
                        [
                            992.4929,
                            47.5892
                        ],
                        [
                            993.49379,
                            3.49349
                        ]
                    ]
                }
            ],
            "_created": "Thu, 01 Jan 1970 00:00:00 GMT",
            "_id": "OCCJIYGVXVWSGD-KQIHHXPCSA-N",
            "_etag": "6c7e13fd17f4877b5cc1afac4a1b4fd3aad7b3c2",
            "Identification Information": {
                "Name": "CL(8:0/8:0/8:0/11:0)",
                "Molecular Formula": "C44H84O17P2"
            }
        }
    ],
    "_meta": {
        "max_results": 50,
        "page": 1
    }
}

但是,如果我尝试限制adduct对象:

http://127.0.0.1:5000/api/metabolites/?where={"Adducts" : {"$elemMatch" : {"Adduct" : {"$in" : ["[M+Na]1+"]}, "Polarity" : "Positive",  "Accurate Mass" : {"$lte" : 991.5, "$gte" : 991.48}}}}&projection={"Identification Information.Name" : 1, "Identification Information.Molecular Formula" : 1, "Adducts.Positive.$":1}&max_results=60}}

返回以下错误;_idRMGKGCYVUJKQSS。。。应该符合标准。你知道吗

{
    "_items": [],
    "_meta": {
        "max_results": 50,
        "page": 1
    }
}

但是,如果我将polarity字段更改为其他内容(负数或中性),那么我就可以毫无问题地使用$in运算符。你知道吗


Tags: nameinformationresultsmaxjanmassgmtformula