Can we use special characters in primary key as well as DBRef

I have two collection user and email. I am using spring data mongo db. See below classes.


class User {

private String userId;
..........
}


class Email {
private String id;
@DBref
private User user;

}

So here user has userId like user.name@host.com. So can we use it as _id as well as dbref. We have index on those id as well

Hi @Salman_Khandu and welcome to MongoDB community forums!!

The DBRefs in MongoDB provide a common format and type to represent relationships among documents.

However this is a convention instead of a server feature, and so it comes with the tradeoff of having to do multiple queries to the database to resolve the references.

Could you please provide more information regarding the code snippet you shared? I have a few questions to better understand the requirements:

  1. It seems that the username and email variables have the same value in the code snippet. Could you clarify the reason for having two separate classes for the same email address?
  2. Can you provide the schema for both classes and explain how they are interdependent?
  3. What are the advantages of having two distinct classes in your application? How does it benefit the overall functionality?

I would appreciate if you could provide additional details to help me grasp the context more accurately.

Regards
Aasawari