Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于mongoose js中的条件填充不工作_Javascript_Node.js_Mongodb_Express_Mongoose - Fatal编程技术网

Javascript 基于mongoose js中的条件填充不工作

Javascript 基于mongoose js中的条件填充不工作,javascript,node.js,mongodb,express,mongoose,Javascript,Node.js,Mongodb,Express,Mongoose,我有两个模式 var Schema = require('mongoose').Schema; var DeviceSchema = new Schema({ name: { type: String }, code: { type: String, unique: true }, os: { type: String }, userEmail: { type:

我有两个模式

var Schema = require('mongoose').Schema;
var DeviceSchema = new Schema({
    name: {
        type: String
    },
    code: {
        type: String,
        unique: true
    },
    os: {
        type: String
    },
    userEmail: {
        type: String
    },
    checkoutTime: {
        type: Date

    },
    tags: {
        type: [String]

    }

});
module.exports = DeviceSchema;

var Schema = require('mongoose').Schema;
var TrackHistorySchema = new Schema({
    userEmail: {
        type: String
    },
    device: {
        type: Schema.ObjectId,
        ref: 'Device',
        required: true
    },
    checkinTime: {
        type: Date
    },
    checkoutTime: {
        type: Date,
        'default': Date.now
    }

});
module.exports = TrackHistorySchema;
我有一个搜索跟踪历史记录,其中包含用户电子邮件id和设备名称

如果我使用历史记录表中的电子邮件条件,则此功能有效

TrackHistory.find({'userEmail': req.query.searchText})
                    .populate({path: 'device'})
                    .sort('-name')
                    .skip(page * maxHistoryPerPage)
                    .limit(maxHistoryPerPage)
                    .exec(next);
但若我使用设备表中的设备名称条件,它将不起作用

TrackHistory.find({})
                    .populate({path: 'device', match: {name: req.query.searchText}})
                    .sort('-name')
                    .skip(page * maxHistoryPerPage)
                    .limit(maxHistoryPerPage)
                    .exec(next);
我得到的所有历史记录行的设备列都为空,就像mysql中的左连接一样。我想要一个类似内部连接的功能,即如果设备名称不匹配,那么相应的历史记录行也不应该显示。我尝试了mongoose文档中的不同组合。也尝试了where子句

我正在使用mongoose 3.6.2(目前最新版本)

编辑-添加模型代码
你能把模型初始化也展示一下吗?重要的是,您应该将引用称为模型的名称,而不是DeviceSchema中的模式。我已经编辑并包含了模型初始化。
var mongoose = require('mongoose');
var DeviceSchema = require('../schemas/device');
var Device = mongoose.model('Device', DeviceSchema);
module.exports = Device;

var mongoose = require('mongoose');
var TrackHistorySchema = require('../schemas/track_history');
var TrackHistory = mongoose.model('TrackHistory', TrackHistorySchema);
module.exports = TrackHistory;