Say I have a User schema/model and the user has a list of friends. Mongoose wants you to store your list of friends (foreign key / ObjectID type) as an array, right? Which means if I want to find my friend by ID, Mongoose will search the array until it finds the first instance of a friend with the ID I want. That seems really time inefficient no? Is there a better way?
const FriendSchema = new Schema({
username: { type: String, required: true, unique: true },
});
const UserSchema = new Schema({
username: { type: String, required: true, unique: true },
friends: [FriendSchema],
});