Filter the default view records for a Mongo DB Collection

Expected behavior

I have a MongoDB collection named Clients which has an optional boolean field deleted. In the default view of the collection in Forest Admin, I want to filter out the clients which have this boolean setup as deleted: true. The idea is to have another segment which will display only the clients with this field being true (I have already achieved this).

I looked at collection overrides, but there is no read functionality to override.

I also looked into the collection hooks for listing the items, both before and after. I wasn’t able to find documentation around altering the default results.

The desired code will look something like this:

  collection.addHook('After', 'List', async (context) => {
    context.records = context.records.filter(record => record.deleted);
  });

OR

  collection.addHook('After', 'List', async (context) => {
    return context.records.filter(record => record.deleted);
  });

Would appreciate some clarification if this is actually possible. Thank you!

Context

  • Agent technology: NodeJS
  • Agent (forest package) name & version: @forestadmin/agent 1.35.16, @forestadmin/datasource-mongoose 1.7.3
  • Database type: Mongo DB

Hello @Mihai_Chiciu1,

You should be able to do that by creating a scope on your team.

Otherwise we currently do not allow to override the default list behaviour on @forestadmin/agent.
I could also suggest that you create 2 segments; one with deleted: true and the other with deleted: false.

If the deleted rows bother you in your main collection you can also override the default sort behaviour so they are not present in your first results. You can do so using the replaceFieldSorting on the pk of your table as it is sorting on it by default.

Best regards,