Modelling a NoSQL Forum Application with C# / ASP.net MVC Modelling a NoSQL Forum Application with C# / ASP.net MVC mongodb mongodb

Modelling a NoSQL Forum Application with C# / ASP.net MVC


Normally in MongoDB, you would embed the answers inside the question. 99% of the time you're going to query by Question, so you might as well get the Answers at the same time.

Some requirements are that i'll need to be able to display a count of answer...

If you're bringing back the answers with the questions, this is really easy. You'll have an array/list/collection with answers. So you'll just grab the length.

but how can I insert an answer, without retrieving the entire post

MongoDB supports an atomic "$push" operation. That means that you can add an item to an array without actually loading the document from the client. From the javascript shell, it would look like this:

db.questions.update( {_id : your_id}, { $push : { answers : your_answer_object } } );

So MongoDB is capable of this. You'll have to check with the NoRM drivers to ensure that they actually allow for this type of behavior (they're really missing something if they don't support $push).


Answer should be part of the question.

public class Question { public string ID { get; set; }

    public string Title { get; set; }    public string Body { get; set; }    public List<string> Tags { get; set; }    public DateTime DateCreated { get; set; }    public string ForumID { get; set; }    public List<Answers> Answers { get; set; }}

Because of the lack of joins document databases encourage you to store instances of the entire graph in one document.