When you have a collection (users_preferences or libraries) with a relationship attribute pointing to users_profiles, creating a document in users_preferences or libraries might also be attempting to create a document in users_profiles implicitly, using the same ID.
Check your code where you're creating documents in users_preferences and libraries. Make sure youre providing the ID of an existing users_profiles document, rather than unintentionally triggering the creation of a new one.