1
나는 Nodejs와 mongodb에 초보자입니다.
다음 시나리오에서 데이터를 가져 오려고했습니다. 프로필 스키마
var ProfileSchema = new Schema({
username: {type: String, match: /^[a-zA-Z0-9_.-]+$/, unique: true},
name: String});
게시물 스키마를 다음과 같이 3 스키마를 고려
var PostsSchema = new Schema({
profileid: {type: ObjectId, ref: 'Profile'},
message: {type: String, match: /^.{1,160}$/} });
스키마 트위터 계층 구조와 유사하다
var FollowSchema = new Schema({
profileid: {type: ObjectId, ref: 'Profile'},
followingid: {type: ObjectId, ref: 'Profile'}});
을 따릅니다.
내 추종자의 모든 게시물을 얻기 위해 나는 다음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);
});
});
을 시도하지만 작동하지 않습니다. 이 문제를 해결하는 가장 좋은 방법을 안내하십시오. (가) 수집 다음에 지원을
덕분에
의 컬렉션 다음 쿼리보십시오, 당신은이 '사용자 ID'필드에 모음 다음에 질의하고 있지만 그 스키마에없는 것 같습니다. 질문에 전체 스키마를 표시하는 FollowsSchema가 있습니까? – shelman
@shelman 제 잘못, 그것은 userID가 아닌 queryI입니다. –
'select ('followingid -_id')'란 무엇인가요?'select ('followingid')' –