I have user Model, which reference to ListedStocks,
@referencesMany(
() => ListedStocks,
{},
{
mongodb: {dataType: 'ObjectId'},
},
)
stockIds?: string[];
But when i try to Create a user and pass an Array of Stocks _id, it gives me an error.
Error: Entity not found: ListedStocks with id "constraint {\"_id\":[\"62eeb4b42b59f883f02f381b\"]}"
When i tried To Debug this, I saw this Query.
loopback:connector:mongodb all ListedStocks { where: { _id: [ '62eeb4b42b59f883f02f381b' ] } } null []
shouldn't where : {_id: []} be where: {_id: {$in: []}}
Or am i missing something?
The Issue was in the constraint created by the
createReferencesManyAccessorThe constraint
const constraint: any = {[primaryKey]: foreignKeyValue};should have beenconstraint = {[primaryKey]: {inq:foreignKeyValue}};Complete Fix is Below.
NOTE: This fix is specifically for the MongoDB, not sure if this breaks SQL Based Repos