我怎么能用密钥作为令牌在php中查询mongodb?

时间:2017-09-30 18:40:17

标签: php mongodb

这是mongo文档。  我需要使用相关令牌提取所有数据的代码。

{
"_id": {
    "$oid": "59cfb47b78a26d86cc5fdd7a"
},
"event": "Coding",
"data": [
    {
        "first_name": "Chanchal",
        "last_name": "Roshan",
        "email": "chan@gmail.com",
        "phone": "75044",
        "college": "AIT",
        "members": "1",
        "amount": "25",
        "branch": "IT",
        "token": "684695669",
        "event": "Coding"
    },
    {
        "first_name": "Ravi",
        "last_name": "Raj",
        "email": "i@gmail.com",
        "phone": "89746",
        "college": "AIT",
        "members": "1",
        "amount": "250",
        "branch": "IT",
        "token": "128027522",
        "event": "Coding"
    }
],
"auth_token": "z1iZ0LnDHFhs48PlYjNHyCjeh7y1"

}

我是php新手,对不起这些基本问题。

1 个答案:

答案 0 :(得分:1)

我假设您的意思是给定令牌XXX,找到data数组的元素包含token="XXX"的所有文档,并返回该数组的元素,而不是整个数组。这应该工作。注意data.token以及在投影(arg 2)中使用$位置运算符:

db.foo.find({"data.token":"XXX"},{"data.$":1});