populate
modify user_id
to an user object
virtual
user
as a virtual and mark user_id
as local_field
.
parent.findOne({isFeatured: true})
?
await db.page.findOne({ _id: myId }).populate('img')
?
ref
?
strict: false
in the first place?
const pageSchema = schema(
joi.object({
title: joi.string().required(),
roles: joi.string().allow(''),
public: joi.boolean().required(),
slug: joi.string(),
published: joi.boolean().required(),
model: joi.string().required().meta({
type: 'ObjectId',
ref: 'Model'
}),
createdBy: joi.string().required(),
}),
{
strict: false,
timestamps: true,
minimize: false,
}
)
ref
there
services
and one with model portfolio
const pageObj = page.toJSON()
for (const field in pageObj) {
const fieldEl = pageObj[field]
if (fieldEl.type === 'imageEl') {
for (const [i, pageId] of fieldEl.pageIds.entries()) {
fieldEl.pageIds[i] = await db.image.findOne({ _id: pageId })
}
}
}
strict: false
#!/usr/bin/env node
'use strict'
const joi = require('joi')
const mongoose = require('mongoose')
const x = joi.object({
title: joi.string().required(),
roles: joi.string().allow(''),
public: joi.boolean().required(),
slug: joi.string(),
published: joi.boolean().required(),
model: joi.string().required().meta({
type: 'ObjectId',
ref: 'Model'
}),
createdBy: joi.string().required()
}, { strict: false })
const M = mongoose.model('test', x)
const m = new M({
title: '234',
roles: '234',
public: true,
slug: '234',
published: true,
model: '234',
createdBy: '234'
})
console.log(m)
output:
gitter: ./wtf.js
/Users/lineus/dev/Help/mongoose5/node_modules/mongoose/lib/schema.js:602
throw new TypeError('Undefined type `' + name + '` at `' + path +
^
TypeError: Undefined type `undefined` at `isJoi`
Did you try nesting Schemas? You can only nest using refs or arrays.
what am I doing wrong to make this work?
await testimony[0].populate('org').execPopulate()
is stalled. testimony[0]
is an EmbeddedDocument. Am I missing something?
testimony[0]
model or id?
testimony
is array of ids on some schema, so what am I asking is have you done MySchema.find({}).populate('testimony')
or not?
.populate('testimony.org')
testimony
subdocuments, and not just testimony[0]
$lookup
stage which will take only first testimony
and populate it
testimony[0]
is...
.populate
on subdoc...
testimony[0].org = await Org.findById(testimony[0].id)