无法在奇怪的特定查询中使用$ in参数

时间:2017-12-18 19:53:07

标签: python mongodb flask eve

我正在使用Python-Eve从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}}

返回以下内容,这是不正确的; _id RMGKGCYVUJKQSS ...应符合标准。

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

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

0 个答案:

没有答案