Whats the Blender 2.8 command for adding an object to a collection using python? I currently have a method that does:

self.myCol = bpy.data.collections.new(self.collection_name)
bpy.context.scene.collection.children.link(myCol)


This method creates and adds a new collection to the outliner. Next, I want to create a bunch of cubes and add those cubes to the collection. How can I tell blender to create objects only within that particular collection? 

Something like:

bpy.ops.mesh.primitive_cube_add(collection='name', size=2, location=(0, 0, 0))


Obvious cube_add doesn't have the param for it, so what's the proper way to do this?
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