'how to get the refrence object data in mern

Suppose i have a Schema Order which have field

Order= {
 _id: {
      type: String,
      required: true,
    },
 user: {
    type: mongoose.Schema.ObjectId,
    ref: "User",
    required: true,
  },
}

Now when I send this data to the frontend I only get id of the user is there any way I can access the data of that user I try to do user.name but it does not work

Note:: Its my mern project



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source