mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
fix mongo preview when array is missing (#8887)
This commit is contained in:
parent
7fa67d8f62
commit
f8f7a4a89f
@ -412,7 +412,7 @@ const buildLookupMatch = ({ assoc, assocModel, filters = {} }) => {
|
|||||||
$match: {
|
$match: {
|
||||||
$and: defaultMatches.concat({
|
$and: defaultMatches.concat({
|
||||||
$expr: {
|
$expr: {
|
||||||
$in: ['$_id', '$$localAlias'],
|
$in: ['$_id', { $ifNull: ['$$localAlias', []] }],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@ -424,7 +424,7 @@ const buildLookupMatch = ({ assoc, assocModel, filters = {} }) => {
|
|||||||
$match: {
|
$match: {
|
||||||
$and: defaultMatches.concat({
|
$and: defaultMatches.concat({
|
||||||
$expr: {
|
$expr: {
|
||||||
$in: ['$_id', '$$localAlias'],
|
$in: ['$_id', { $ifNull: ['$$localAlias', []] }],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@ -435,7 +435,7 @@ const buildLookupMatch = ({ assoc, assocModel, filters = {} }) => {
|
|||||||
$match: {
|
$match: {
|
||||||
$and: defaultMatches.concat({
|
$and: defaultMatches.concat({
|
||||||
$expr: {
|
$expr: {
|
||||||
$in: ['$$localId', `$${assoc.via}`],
|
$in: ['$$localId', { $ifNull: [`$${assoc.via}`, []] }],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -550,7 +550,11 @@ module.exports = ({ model, strapi }) => {
|
|||||||
return model
|
return model
|
||||||
.aggregate()
|
.aggregate()
|
||||||
.match({ [model.primaryKey]: { $in: entitiesIds.map(mongoose.Types.ObjectId) } })
|
.match({ [model.primaryKey]: { $in: entitiesIds.map(mongoose.Types.ObjectId) } })
|
||||||
.project({ _id: 0, id: '$_id', count: { $size: `$${assoc.alias}` } });
|
.project({
|
||||||
|
_id: 0,
|
||||||
|
id: '$_id',
|
||||||
|
count: { $size: { $ifNull: [`$${assoc.alias}`, []] } },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const assocModel = strapi.db.getModelByAssoc(assoc);
|
const assocModel = strapi.db.getModelByAssoc(assoc);
|
||||||
return assocModel
|
return assocModel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user