如何只用吸气剂的内容填充

时间:2019-03-27 18:58:40

标签: mongoose-populate

我的猫鼬项目有问题。 我尝试填充并使用吸气剂,但不是所有数据 但是现在所有虚拟文件都出现在文档中。 我正在使用 @GetMapping("/") public String listProjects(Model theModel) { /* * To get the username using Spring Security */ Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String username = auth.getName(); theModel.addAttribute("username", username); Team theTeam = new Team(); theModel.addAttribute("team", theTeam); /* * Get the current user by username */ User user = userService.findByUsername(username); /* * Get the teams of the current user */ List<Team> theTeams = user.getTeams(); //Add teams to the model attribute theModel.addAttribute("teams", theTeams); System.out.println("This is a test " + username); return "home"; } mongoose.Schema

这是我的测试代码示例

mongoose.Model

填充文档

const GroupsSchema = schema({
    title: String,
    users: [{
        type: schema.Types.ObjectId,
        ref: 'Users'
    }]
});

const UsersSchema = schema({
    name: String,
    avatar: String
}, {
    toJSON: {
        virtuals: true
    }
});

class Users extends Model {
    get name() {
        return {
           name: this.name
        };
    }
    get avatar() {
        return {
           avatar: this.avatar
        };
    }
}

我当前的结果:

const groups = await Groups.find({}).populate('users').exec();

如何仅使用[ { "_id": "5c9bb51626924f0a08aa8c3d", "title": "GroupName" "users": [ { "_id": "5c8e37169fc1f9000f8c333b", "name": "Jack", "avatar": "avatar.jpg", "name": { "name": "Jack", }, "avatar": { "avatar": "avatar.jpg" } } ] } ] 吸气剂填充内容?

所需结果:

name

0 个答案:

没有答案