我正在尝试从用户模型获取填充数据。但是,人口没有工作。 我期待用户模型提供Cat数据。用户中没有猫数据。
这是我的猫模式。
const mongoose = require('mongoose');
const catSchema = new mongoose.Schema({
name: {
type: String,required: true,},accessibility: {
type: String,friendliness: {
type: String,likes: [{
type: mongoose.Schema.Types.ObjectId,ref: 'User',}],founder: {
type: mongoose.Schema.Types.ObjectId,comments:[{
type: mongoose.Schema.Types.ObjectId,ref: 'Comment',location: [],image: {
type: String,time: {
type: String,description: {
type: String,default: '',}
});
module.exports = mongoose.model('Cat',catSchema);
这是我的用户架构。
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
facebookId: {
type: String,name: {
type: String,cats: [{
type: mongoose.Schema.Types.ObjectId,ref: 'Cat',});
module.exports = mongoose.model('User',userSchema);
并且我使用这段代码来获取填充数据,但是它不起作用
const user = await User.findById(id).populate('Cat');