Fill collection type relations programatically

Hello guys, I was wondering whether it’s possible to fill relations of a collection type programmatically. For example, I have collection types categories, and products. The relation between them is many to many.

This is how I seed categories and products in bootstrap.js:

name: Category ${index},
products: TODO

and this is how I seed products:

name: New Product ${index},
description: Description of New Product ${index},
categories: TODO

Is there even a way to do this programmatically or not, because I have been trying to find an answer to this for some time and no results… Thank you guys in advance, the help is much appreciated.