The correct line of code is b.a_links.add(a)
The issue comes from trying to manually create the Link
object. Beanie is designed to handle this for you automatically. You should add the document object itself to the set. Beanie will convert it into a DBRef
link when you save the document.