lucid-mongo
lucid-mongo copied to clipboard
Cannot read property 'collectionName' of undefined when filtering hasMany relationship
I'm using adonis.js/lucid ^6.1.3 with lucid-mongo ^3.1.5 library to manage ### mongodb database. I need to build a query and filter a hasMany relationship but it throws an exception Cannot read property 'collectionName' of undefined
I've created a model called User and then provided a relation called sessions which must return all user sessions (Mobile or web session). I've used the approach described in adonis.js lucid relationship for querying data of relationships
return await user.sessions().where({
'logged_in_at': { $type: 10 },
'logged_out_at': { $type: 10 }
}).where('tries', '<', 3).firstOrFail();
The expected output should be a session document (row) but this is the exception it throws Cannot read property 'collectionName' of undefined
What's wrong with my code?
had this error message when I was missing .fetch() (or first) after where, don't think it's your issue thus.