I am newbie to Nodejs and mongodb.
I was trying to get data for the following scenario. Consider 3 schemas as follows Profile schema
var ProfileSchema = new Schema({
username: {type: String, match: /^[a-zA-Z0-9_.-]+$/, unique: true},
name: String});
Posts schema
var PostsSchema = new Schema({
profileid: {type: ObjectId, ref: 'Profile'},
message: {type: String, match: /^.{1,160}$/} });
Follows schema
var FollowSchema = new Schema({
profileid: {type: ObjectId, ref: 'Profile'},
followingid: {type: ObjectId, ref: 'Profile'}});
Which is similar to the twitter hierarchy.
To get all the posts from my followers I tried the following
Follows.find({'profileid' : '500d18823e792d8814000001'}).select('followingid -_id').limit(20).sort({addedon: 'desc'}).execFind(function (arr,followings) {
Posts.find({profileid: {$in: followings}}).limit(20).execFind(function (arr,data) {
console.log(data);
});
});
But it is not working. Please guide the best way to get this.
Thanks for your support
select('followingid -_id'), I think it should beselect('followingid')