问题描述
我有一个包含文章的模型,我想用集合中的所有文档填充一个数据数组。
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ArticlesSchema = new mongoose.Schema({
path: {
type: String,required: true,unique: true,},base_headline: {
type: String,intro: {
type: String,featured_image: {
type: String,author: {
type: String,platform_filter: {
type: String,free_filter: {
type: String,content_type: {
type: String,data: [{ type: Schema.Types.ObjectId,ref: 'DesignProducts' }],date: {
type: Date,default: Date.now,});
module.exports = mongoose.model('Articles',ArticlesSchema);
data 属性应填充 DesignProducts 集合中的所有文档。
我尝试运行它,但 data 数组仍然是空的:
Article.findOne({ path: slug }).populate('data').exec();
designProducts 模型如下所示:
const mongoose = require('mongoose');
const DesignProductsSchema = new mongoose.Schema({
name: {
type: String,website: {
type: String,});
module.exports = mongoose.model('DesignProducts',DesignProductsSchema);
此数组应填充 DesignProducts 集合中的所有文档:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)