My schema is shown below :
var productSchema = new Schema({
name : String,
likes : [{
user_id : Schema.Types.ObjectId,
date : Date
}]
});
Assume that I have this collection
{ name : A, likes : [ {user_id : id1, date : blahblah}, {user_id : id2, date : balh}] }
{ name : B, likes : [ {user_id : id1, date : blahblah}] }
{ name : C }
then I want to show, following kinda of output by querying it
(with user_id = id1){ name : A, like : 1}, { name : B, like : 1}, { name : C, like : 0}
(with user_id = id2){ name : A, like : 1}, { name : B, like : 0}, { name : C, like : 0}
So to say, i want to add new field, called 'like' here.
If the user_id exists in array(likes), like is 1, if not, should be zero.
Can i make this happen?