如何解决Mongoose 聚合:无法使用查找填充 2 级嵌套字段
我有三个模型 Institution
、User
和 Profile
机构
const InstitutionSchema = new Schema({
current_students: [
{
type: Schema.Types.ObjectId,ref: "users",},],});
const UserSchema = new Schema({
name: {
type: Schema.Types.String,profile: {
type: Schema.Types.ObjectId,ref: "profiles",});
简介
const ProfileSchema = new Schema({
videoURL: {
type: Schema.Types.String,});
我正在尝试取回机构数组并填充 current_students.user 和 current_students.user.profile:
Institution.aggregate([
{
$lookup: {
from: "users",localField: "current_students",foreignField: "_id",as: "current_students",{
$unwind: {
path: "$current_students",{
$lookup: {
from: "profiles",localField: "current_students._id",foreignField: "profile",as: "current_students.profile",]);
但是,这总是将配置文件字段返回为空。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。