Morphia と Play フレームワークを使用して、1Post
対多の古典的なブログ スキーマを再現しようとしています。Comment
Mongo での私のスキーマは次のとおりです。
{ "_id" : ObjectId("4d941c960c68c4e20d6a9abf"),
"className" : "models.Post",
"title" : "An amazing blog post",
"comments" : [
{
"commentDate" : NumberLong("1301552278491"),
"commenter" : {
"$ref" : "SiteUser",
"$id" : ObjectId("4d941c960c68c4e20c6a9abf")
},
"comment" : "What a blog post!"
},
{
"commentDate" : NumberLong("1301552278492"),
"commenter" : {
"$ref" : "SiteUser",
"$id" : ObjectId("4d941c960c68c4e20c6a9abf")
},
"comment" : "This is another comment"
}
]}
ブログにソーシャル ネットワーキングの側面を導入しようとしているので、すべての投稿にわたって、 の友人SiteUser
による最後の X 件のコメントを のホームページで提供できるようにしたいと考えています。SiteUser
私のモデルは次のとおりです。
@Entity
public class Post extends Model {
public String title;
@Embedded
public List<Comment> comments;
}
@Embedded
public class Comment extends Model {
public long commentDate;
public String comment;
@Reference
public SiteUser commenter;
}
他の場所で読んだことから、データベースに対して次を実行する必要があると思います(ここで[a, b, c]
はsを表しますSiteUser
):
db.posts.find( { "comments.commenter" : {$in: [a, b, c]}} )
フィルタリングのためにモルフィアに渡す必要List<SiteUser>
がありますが、方法がわかりません
- Morphia 内から
Post
forにインデックスを設定するComments.commenter
- 実際に上記のクエリを作成します