How does mongodb perform subqueries

  mongodb, question

User collection, I designed it this way:

User {
    uid: xx,
    name: xxx,
    description: xxxx,
    follow: ["uid1","uid2","uid3",...]
}

How do I write a query statement in order to list all the people that a user follow?

<uid1, name1, description1>
<uid2, name2, description2>
...

Don’t just think of mongodb as a schemeless sql database. mongodb does not have the concept of subquery and cross-table query.

According to your description, if you want to get the detailed information list of all the people who follow a certain User, one way is to save all the information of these users into user:

User {
    uid: xx,
    name: xxx,
    description: xxxx,
    follow: ["uid1": {'name': 'xxx', 'description': 'desc1'},"uid2": {'name': 'zzz', 'description': 'desc2'},...]
}

Or you can use the second query and look it up again in the code.

db.User.find({'uid':{'$in': [uid1, uid2, uid3]}});