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