相关疑难解决方法(0)

在Mongoose中填充后查询

我对Mongoose和MongoDB很新,所以我很难搞清楚这样的事情是否可行:

Item = new Schema({
    id: Schema.ObjectId,
    dateCreated: { type: Date, default: Date.now },
    title: { type: String, default: 'No Title' },
    description: { type: String, default: 'No Description' },
    tags: [ { type: Schema.ObjectId, ref: 'ItemTag' }]
});

ItemTag = new Schema({
    id: Schema.ObjectId,
    tagId: { type: Schema.ObjectId, ref: 'Tag' },
    tagName: { type: String }
});



var query = Models.Item.find({});

query
    .desc('dateCreated')
    .populate('tags')
    .where('tags.tagName').in(['funny', 'politics'])
    .run(function(err, docs){
       // docs is always empty
    });
Run Code Online (Sandbox Code Playgroud)

这有更好的方法吗?

编辑

为任何困惑道歉.我要做的是获取包含有趣标签或政治标签的所有项目.

编辑

没有where子句的文件: …

mongoose mongodb node.js

66
推荐指数
4
解决办法
5万
查看次数

标签 统计

mongodb ×1

mongoose ×1

node.js ×1