Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 1.72 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Trying to fetch documents which contains nested documents
  2. public List<Maps> GetAllMapsByUserId(ObjectId userId)        
  3.                   {            
  4.                       using (_server.RequestStart(_db))            
  5.                       {                
  6.                           var query = Query.EQ("UserId", userId);
  7.                           MongoCursor<Maps> maps = _db.GetCollection<Maps>"Maps").FindAs<Maps>(query);
  8.                           var list = maps.ToList();
  9.  
  10.                           return list;            
  11.                       }
  12.                   }
  13.        
  14. namespace Project.Models
  15. {    
  16.  
  17. public class Maps    {        
  18.  
  19.     [BsonId]        
  20.     public ObjectId Id { get; set; }
  21.     public ObjectId UserId { get; set; }
  22.     public string MapName { get; set; }
  23.     public string Description { get; set; }
  24.     public BsonBoolean PublicMap { get; set; }
  25.     public DateTime Created { get; set; }
  26.  
  27.     [BsonIgnoreIfNull]
  28.     public List<MapTags> Tags { get; set; }
  29.  
  30.     [BsonIgnoreIfNull]
  31.     public List<MapVotes> Votes { get; set; }
  32.  
  33.     }
  34.  
  35. public class MapVotes
  36. {
  37.     public ObjectId VoterId { get; set; }
  38.     public int VoteValue { get; set; }
  39. }
  40.  
  41. public class MapTags
  42. {
  43.     public string Tag { get; set; }
  44. }
  45.  
  46. }
  47.        
  48. {
  49.     "_id" : ObjectId("4eda2415851e702684bf6392"),
  50.     "MapName" : "Test",
  51.     "Description" : "Test",
  52.     "Created" : ISODate("2011-12-03T13:28:53.698Z"),
  53.     "PublicMap" : false,
  54.     "UserId" : ObjectId("4e8033a0851e701c7c1e12e1"),
  55.     "Tags" : [ "Test", "Kalle", "Jonas", "Fredrik" ]
  56.   }
  57.        
  58. {
  59.    "MapName" : "SomeMapName"
  60.    "Tags" : ["tag1", "tag2"] // list of strings
  61.    // ...
  62. }
  63.        
  64. {
  65.    "MapName" : "SomeMapName"
  66.    "Tags" : [ { /* map tag document */ }, { /* map tag document */ }, ...]
  67.    // ...
  68. }