Due to the fact that you need to receive comments on certain attributes, the user, etc., you cannot embed (embedding is always faster for document databases) a comment in each object that users can comment on. Therefore, you need to create a separate collection for comments. I suggest the following structure:
comment { _id : ObjectId, status: int (spam =1, approved =2), userId: ObjectId, commentedObjectId: ObjectId, commentedObjectType: int(for example question =1, answer =2, user =3), commentText }
With the above structure, you can easily do what you need:
//Mark comments as spam/approved and retrieve comments by this attributes //mark specific comment as spam db.comments.update( { _id: someCommentId }, { status: 1 }, true); db.comments.find({status : 1});// get all comments marked as spam //Retrieve comments by user db.comments.find({'_userId' : someUserId}); //Retrieve comment count for an object/user db.comments.find({'commentedObjectId' : someId,'commentedObjectType' : 1 }) .count();
Also, I believe that for comments, it would be better to create an additional field in each object and inc add / delete it in the comment.
Andrew Orsich
source share