Assuming an API /login case where a user object from a collection should be returned for the corresponding set of credentials, which approach would be more efficient:
1) One model with projection requests:
var UserSchema = new Schema({ name : String, email : String, dob : Number, phone : Number, gender : String, location : Object,
2) Separation models:
var UserMinimalSchema = new Schema({ name : String, email : String, phone : Number, location : Object, }); var UserDetailSchema = new Schema({ dob : Number, gender : String, followers : [UserSchema], following : [UserSchema], posts : [PostSchema], groups : [GroupSchema]
Say:
For a registered user, only id , name , email , phone and location should be returned.
The first model will use a projection query to return properties in (1).
In the second case, only UserMinimalSchema will be used to query the entire document.
In fact, both queries return exactly the same amount of data as indicated in (1).
Suppose the average user object has a limit of ~ 16 MB and there are 1 million records.
If someone has performed such a test / documentation link, it would be very helpful to see how important it is for separation or not.
source share