mongodb - Mongo DB Nested CRUD c# -


hi starting build cms around mongo db c#.

i have basic document looks fields removed simplicity here...

{ "_id" : objectid("518438c35ea2e913ec41c138"), "content" : "some html content here", "title" : "robs article", "author" : "rob paddock", "dateposted" : isodate("0001-01-01t00:00:00z"), "articlestatus" : "live" } 

to call document have following code

public ienumerable<article> getarticledetails(int limit, int skip)     {         var articlescursor = this.mongoconnectionhandler.mongocollection.findallas<article>()             .setsortorder(sortby<article>.descending(a => a.title))             .setlimit(limit)             .setskip(skip)             .setfields(fields<article>.include(a => a.id, => a.title, => a.author));         return articlescursor;     } 

to create new document have

 public virtual void create(t entity)     {         //// save entity safe mode (writeconcern.acknowledged)         var result = this.mongoconnectionhandler.mongocollection.save(             entity,             new mongoinsertoptions             {                 writeconcern = writeconcern.acknowledged             });          if (!result.ok)         {             //// went wrong         }     } 

my question how alter above allow "content" list may want have mutiple content blocks on page.

public class article {     public bsonobjectid id { get; set; }     public list<string> content { get; set; }     public string title { get; set; }     public string author { get; set; }     public string dateposted { get; set; }     public string articlestatus { get; set; }      public void addcontent(string c)     {         if (content == null)         {             content = new list<string>();         }         content.add(c);     } } 

...

        var article = new article { title = "robs article", author = "rob paddock", dateposted="1/1/1980", articlestatus="live" };         article.addcontent("some html content here");         article.addcontent("nyt featured");         article.addcontent("recommended gourmets");          var articlecollection = database.getcollection<article>("articles");         articlecollection.insert(article); 

...

> db.articles.find() { "_id" : objectid("5185358ee153db0e0c6fa36a"), "content" : [ "some html content here",   "nyt featured", "recommended gourmets" ], "title" : "robs article", "author" : "rob  paddock", "dateposted" :  "1/1/1980", "articlestatus" : "live" } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -