简体   繁体   English

猫鼬填充不返回结果

[英]Mongoose populate not returning results

I am trying to use populate to return results that are ref to the Stamp model, under the users array of stamps but for some reason it does not return any results when I see in the database a list of stamp ids in the stamps array... 我正在尝试使用填充返回在图章的用户数组下返回到图章模型的结果,但是由于某些原因,当我在数据库中看到图章数组中的图章ID列表时,它不返回任何结果。 。

Here is my code: 这是我的代码:

var selectQuery = "_id name";
    var populateQuery = [{path:'stamps', select: selectQuery, model: 'Stamp', }];
    User.findOne({_id: userId}).populate(populateQuery).sort({date: -1}).skip(count).limit(100).exec(function(err, results) {
        if(err) {

Here is the User Schema 这是用户架构

var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = mongoose.Schema.Types.ObjectId,
var Stamp = require('../models/stamp.js');

var User = new Schema({ 
    name: { type: String},

    stamps: [{ type: ObjectId, ref: 'Stamp' }],

The "query" form of populate doesn't take an array as argument, but an object: populate的“查询”形式不以数组作为参数,而是一个对象:

// `model` can be left out as Mongoose will look that up in the schema
var populateQuery = { path : 'stamps', select : selectQuery };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM