MongoDB多表查询

1. $lookup

db.Article.aggregate([
    {
        $lookup: {
            from: "Category",
            as: "Category",
            localField: "CategoryId",
            foreignField: "_id"
        }
    }
])

2. 嵌套语句

db.Article.find({
    CategoryId: {
        $in: db.Category.find().toArray().map(x => x._id)
    }
})

你可能感兴趣的:(MongoDB多表查询)