0

你能帮我从两个集合中生成一个 json:

用户 [ user_id, user_name, city_id ]

[
    {
        "name": "Anton",
        "user_id": 1,
        "city_id": 1
    },
    {
        "name": "Vasiliy",
        "user_id": 2,
        "city_id": 2
    }
]

城市 [ city_id, city_name ]

[
    {
        "name": "Kharkov",
        "city_id": 1
    },
    {
        "name": "Kiev",
        "city_id": 2
    }
]

JSON 像这样:

[
        {
            "user_name": "Anton",
            "city_name": "Kharkov",
            "user_id": 1,
        },
        {
            "user_name": "Vasiliy",
            "city_name": "Kiev",
            "user_id": 2,
        }
]
4

1 回答 1

0

您需要在应用程序层中进行连接,无法连接 MongoDB 中的数据。每当您在两个集合中有数据时,您都必须发出两个查询。

于 2013-08-29T16:00:00.470 回答