私は 2 つの MongoDB コレクションを持ってCustomer
おりUser
、1:1
関係にあります。Mongoose Populationを使用して両方のドキュメントをクエリし、 で並べ替えようとしていますUser.name
。
以下は何も機能していません。私のマングースは 3.8.19 です。
Customer
.find({})
.populate("user", "name email phone")
.sort({ "name": 1 })
.exec()
Customer
.find({})
.populate("user", "name email phone", null, { sort: { 'name': 1 } } )
.exec()
Customer
.find({})
.populate({
path: "user",
select: "name email phone",
options: { sort: { "name": 1 }}
}).
exec()
Customer
.find({})
.populate({
path: "user",
select: "name email phone",
options: { sort: [{ "name": 1 }]}
})
.exec()
検索条件で入力されたドキュメントを並べ替える方法を見つけましたか? 、しかし私にとっては成功しません。
SQL では以下のようになります。
SELECT customer.*, user.name, user.email, user.phone FROM customer
JOIN user ON customer.user_id = user.id
ORDER BY user.name ASC