如何从C#运行任何mongodb查询

时间:2013-09-13 03:09:13

标签: c# mongodb

我想从C#运行这个mongodb查询:

db.Stories.find({_id: ObjectId("52318492c28f7c19d4270c7f")},
                {Chapter:
                     {$elemMatch:{
                           ChapId:ObjectId("52318629c28f7c1ec4515000")

                           }}
})

2 个答案:

答案 0 :(得分:1)

尝试做这样的事情:

var server = MongoServer.Create("mongodb://localhost:27020");
var database = server.GetDatabase("someDb");

var collection = database.GetCollection<Type>("someCollection");
var searchQuery = Query.GT("myfield", 10).LT(20);
var list = collection.Find(searchQuery);

参考:MongoDB C# Query expression (How to?)

答案 1 :(得分:0)

Query.GT是什么意思 我的收藏是这样的 我想在chapid的一章中得到这个章节

"AuthorName" : "From",
        "CateName" : "biết chết liền",
        "Chapter" : [ 
            {
                "ChapContent" : [ 
                    {
                        "ImgUrL" : "../Upload/Stories/523675fec28f7c04b088afd6/52367611c28f7c04b088afd7/12613_617411151612439_796025785_n.jpg",
                        "Page" : 1,
                        "PageId" : ObjectId("52367612c28f7c04b088afd8")
                    }, 
                    {
                        "ImgUrL" : "../Upload/Stories/523675fec28f7c04b088afd6/52367611c28f7c04b088afd7/21453_617411254945762_2771189_n.jpg",
                        "Page" : 1,
                        "PageId" : ObjectId("52367612c28f7c04b088afd9")
                    }, 
    "DatePost" : ISODate("2013-09-16T03:07:42.096Z"),
    "Description" : "dsngdsfhgdsjhfgds",
    "FirstCharacter" : "b",
    "LastModify" : ISODate("2013-09-16T03:07:42.096Z"),
    "Status" : 1,
    "StoryName" : "biết ai",
    "Title" : "ai biêt",
    "_id" : ObjectId("523675fec28f7c04b088afd6")