0
示例:让我们假设以下集合。 ThrashMetalDocumentsCollection和SpeedMetalDocumentsCollection,这两个集合具有相同的HeavyMetalRecordDocument结构,如下所示。如何查询并返回两个集合中的所有记录,并按发布日期(最早的最早)和评分(最高到最低)对它们进行排序?谢谢! \ M/\ M/MongoDB使用排序顺序查询两个集合
static async Task getAllRecords()
{
var builder = Builders<HeavyMetalRecordDocument>.Filter;
//var filter;
using (var cursor = await ThrashMetalDocumentsCollection.Find()
.Sort(Builders<HeavyMetalRecordDocument>.Sort.Ascending(x => x.rating))
.ToCursorAsync())
{
while (await cursor.MoveNextAsync())
{
foreach (var doc in cursor.Current)
{
//Do Something…
}
}
}
}
public class HeavyMetalRecordDocument
{
public ObjectId Id { get; set; }
public String artist { get; set; }
public String title { get; set; }
public DateTime releaseDate { get; set; }
public int rating { get; set; } // 1-10
}
我会做一些小的调整,并将范围限制为一个集合。谢谢! – 80sRocker