Whats the Blender 2.8 command for adding an object to a collection using python?
Your answer is actually wrong.

If your active collection is another as the main collection, when running your script the object will not be removed from this.

import bpy

bpy.ops.mesh.primitive_cube_add()
# our created cube is the active one
obj = bpy.context.active_object
# Remove object from all collections not used in a scene
bpy.ops.collection.objects_remove_all()
# add it to our specific collection
bpy.data.collections['MyCollection'].objects.link(obj)


About remove all:
https://docs.blender.org/api/blender2.8/bpy.ops.collection.html#bpy.ops.collection.objects_remove_all