c# - MongoDB + NoRM- Concurrency and collections -
lets have following document structure:
class blogpost { [mongoidentifier] public guid id{get;set;} public string body{get;set;} .... } class comment { [mongoidentifier] public guid id{get;set;} public string body {get;set;} }
if assume multiple users may post comments same post, best way model relation between these?
if post have collection of comments, might concurrency problems, won't ?
and placing fk attribute on comment seems relational , or?
you have 2 options: 1. aggregate comments in post document, or 2. model post , comment documents.
if aggregate comments, should either a) implement revision number on post, allowing detect race conditions , implement handling of optimistic concurreny, or b) add new comments mongodb modifier - e.g. like
var posts = mongo.getcollection<post>(); var crit = new { id = postid }; var mod = new { comments = m.push(new comment(...)) }; posts.update(crit, mod, false, false);
if model post , comment separate documents, handling concurrency easier, lose ability load post , comments single findone
command.
in opinion, (1) far interesting option because models post aggregate object, when put oo glasses on :). it's document-oriented approach, whereas (2) resembles flat structure of relational database.
Comments
Post a Comment