【问题标题】:Mongoose find in nested Schema猫鼬在嵌套模式中查找
【发布时间】:2019-07-20 13:04:12
【问题描述】:

我尝试使用 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);
}

用户模型

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:

【问题讨论】:

    标签: javascript mongodb typescript mongoose nested-queries


    【解决方案1】:

    使用点符号:

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

    【讨论】:

      猜你喜欢
      • 2019-03-22
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 2015-09-21
      • 2014-06-22
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      相关资源
      最近更新 更多