How to create smart relation in forestadmin/agent

Feature(s) impacted


I am trying to migrate smart relationship from forest-express-mongoose v9 to forestadmin/agent.

I want to have a smart field reference to other collection and following this v9 document

collection('config', {
	actions: [],
	fields: [
			field: 'user',
			type: 'String',
			reference: 'users',
			isReadOnly: true,
			get: async (config) => {
				const user = await findById(config.f_id.user_id);
				return user;
			async search(search) {
				const user = await findById(search);
				if (user == null) return;
				const fRecords = await fService.find({ user_id: user._id }, { _id: 1 });
				const fIds = => f._id);
				return { f_id: { $in: fIds } };

In new document I see reference has been removed. Is there a way I can create relationship for smart field.

I tried to add relationship but got error Column not found: 'config.user' which make sense that config collection mongoose schema doesn’t have user.

Observed behavior

Expected behavior

Failure Logs


  • Project name: OrthograhIQ
  • Team name: …
  • Environment name: dev
  • Agent technology: nodejs
  • Agent (forest package) name & version:
  • forestadmin/agent 1.40.0
  • forestadmin/datasource-mongoose 1.7.6
  • Database type: mongo

Hello @NathanLe,

We’re thrilled to see that you’re taking the step to migrate to the new @forestadmin/agent

The new interface for a smart field with a reference is named a Smart Relationship, you can find an example in this section of the migration steps.

The exercise of switching between forest-express-mongoose to the new @forestadmin/agent can be arduous, so we tried to make a migration guide as detailed as possible to guide users through each step. It will certainly be helpful if you were not aware of its existence.

Best regards,

1 Like