2012-04-17 56 views
0

我想插入带有子项的记录,然后在c#中的屏幕上显示所写的内容。这是我到目前为止:mongo bson插入/读取子记录

MongoCollection<BsonDocument> house= building.GetCollection<BsonDocument>("house"); 
    BsonDocument rooms= new BsonDocument { 
       { "roomName", name}, 
       { "location", <--child array here: 1stfloor, 2ndlfloor, topfloor. 
       { "roomID", guidstring} 
       }; 

    house.Insert(rooms); 

回答

0

您的意思是为了调试目的?您可以将文档转换为JSON字符串:

Console.WriteLine(rooms.ToJson()); 

您也可以使用mongo shell来查看您的文档。运行蒙戈外壳,然后键入:

> use buildings // or whatever your database name is 
> db.house.find() 
... your documents displayed here 
> 

如果您收藏有大量的文件,你可能会想包括一些类型的查询,以缩小其显示的文档。

您还应该考虑使用C#类定义域模型,并让驱动程序将它们转换为BSON文档并从BSON文档转换为您。