
Untitled
By: a guest on
May 17th, 2012 | syntax:
None | size: 1.72 KB | hits: 13 | expires: Never
Trying to fetch documents which contains nested documents
public List<Maps> GetAllMapsByUserId(ObjectId userId)
{
using (_server.RequestStart(_db))
{
var query = Query.EQ("UserId", userId);
MongoCursor<Maps> maps = _db.GetCollection<Maps>"Maps").FindAs<Maps>(query);
var list = maps.ToList();
return list;
}
}
namespace Project.Models
{
public class Maps {
[BsonId]
public ObjectId Id { get; set; }
public ObjectId UserId { get; set; }
public string MapName { get; set; }
public string Description { get; set; }
public BsonBoolean PublicMap { get; set; }
public DateTime Created { get; set; }
[BsonIgnoreIfNull]
public List<MapTags> Tags { get; set; }
[BsonIgnoreIfNull]
public List<MapVotes> Votes { get; set; }
}
public class MapVotes
{
public ObjectId VoterId { get; set; }
public int VoteValue { get; set; }
}
public class MapTags
{
public string Tag { get; set; }
}
}
{
"_id" : ObjectId("4eda2415851e702684bf6392"),
"MapName" : "Test",
"Description" : "Test",
"Created" : ISODate("2011-12-03T13:28:53.698Z"),
"PublicMap" : false,
"UserId" : ObjectId("4e8033a0851e701c7c1e12e1"),
"Tags" : [ "Test", "Kalle", "Jonas", "Fredrik" ]
}
{
"MapName" : "SomeMapName"
"Tags" : ["tag1", "tag2"] // list of strings
// ...
}
{
"MapName" : "SomeMapName"
"Tags" : [ { /* map tag document */ }, { /* map tag document */ }, ...]
// ...
}