如何在mongodb中为orderby编写查询按C#排序?

时间:2015-05-10 10:17:48

标签: c# mongodb

我有一个类似

的BsonDocument
{"_id" : "cf7efefd-91f3-4b55-8233-976a08beba69",    
"_P21id" : "#1",    
"_EntityName" : "IfcCartesianPoint",    
"_v" : "(0.,0.,0.)" }

{"_id" : "75558818-2c42-4009-8fc2-636b2435debc",
"_P21id" : "#10",
"_EntityName" : "IfcGeometricRepresentationContext",
"ContextIdentifier" : "$",
"ContextType" : "'PLAN'",
"CoordinateSpaceDimension" : "3",
"Precision" : "1.E-005",
"WorldCoordinateSystem" : "#9",
"TrueNorth" : "$"
}

{
    "_id" : "4c4a7f17-eca0-4d1d-98fe-64e8bc319f5e",
    "_P21id" : "#4",
    "_EntityName" : "IfcAxis2Placement3D",
    "Location" : "#1",
    "Axis" : "#117",
    "RefDirection" : "#119"
}

我希望结果顺序为" _P21id"像

{"_id" : "cf7efefd-91f3-4b55-8233-976a08beba69",    
"_P21id" : "#1",    
"_EntityName" : "IfcCartesianPoint",    
"_v" : "(0.,0.,0.)" }

{
    "_id" : "4c4a7f17-eca0-4d1d-98fe-64e8bc319f5e",
    "_P21id" : "#4",
    "_EntityName" : "IfcAxis2Placement3D",
    "Location" : "#1",
    "Axis" : "#117",
    "RefDirection" : "#119"
}

{"_id" : "75558818-2c42-4009-8fc2-636b2435debc",
"_P21id" : "#10",
"_EntityName" : "IfcGeometricRepresentationContext",
"ContextIdentifier" : "$",
"ContextType" : "'PLAN'",
"CoordinateSpaceDimension" : "3",
"Precision" : "1.E-005",
"WorldCoordinateSystem" : "#9",
"TrueNorth" : "$"
}

如何编写查询?

1 个答案:

答案 0 :(得分:0)

使用它:

var sort = SortBy.Ascending("_P21id");
var result = Collection.FindAll().SetSortOrder(sort);