猫鼬在嵌套模式中查找

时间:2019-02-26 21:57:17

标签: javascript mongodb typescript mongoose nested-queries

我尝试使用accountStatus.activated = false来获取所有用户。但是我就是做不到。

User.find({accountStatus: {activated: false}}) ...

controller.ts

import {User} from "../models/userModel";

public static getAllUsers(request, response, next): void {
    User.find().then(data => response.json(data)).catch(next);
}

userModel

const user:Schema = new Schema({
    name_first: {
        type: String,
        required: [true, 'First Name is required (name_first)']
    },
     accountStatus: {
        activated: {
            type: Boolean,
            default: false,
            required: true
        },
     }
});

export const User: Model = model("User", user);

请帮助我D:

1 个答案:

答案 0 :(得分:1)

使用点符号:

User.find({'accountStatus.activated': false})