我对一个集合进行了新查询,该集合已经在为配置的类型拉取并存储数据,而我之前从未遇到过:
signin-oidc
我拥有的对象具有以下结构:
The serializer for field 'BookingRequests' must implement IBsonArraySerializer and provide item serialization info.
其中public class DayBookings : IHasId
{
public DayBookings()
{
BookingRequests = new Dictionary<string, TimestampedRequest<BookingRequest>>();
}
public DayBookings(TimestampedRequest<BookingRequest> bookingRequest, string restaurant) : this()
{
Id = $"{restaurant}_{bookingRequest.Request.Date.ToString("ddMMyyyy")}";
Restaurant = restaurant;
Date = bookingRequest.Request.Date;
BookingRequests[bookingRequest.RequestId] = bookingRequest;
}
public string Id { get; set; }
public string Restaurant { get; set; }
public DateTime Date { get; set; }
public Dictionary<string, TimestampedRequest<BookingRequest>> BookingRequests { get; set; }
}
是其中包含通用数据的标准POCO对象。
我在启动时运行的那个集合的配置是:
TimestampedRequest
我为该字段添加了自定义序列化程序,以防万一,但没有效果。
我要执行的查询是这样:
if (!BsonClassMap.IsClassMapRegistered(typeof(DayBookings)))
{
BsonClassMap.RegisterClassMap<DayBookings>(cm =>
{
cm.AutoMap();
cm.SetIdMember(cm.GetMemberMap(c => c.Id));
var customDictionarySerializer = new DictionaryInterfaceImplementerSerializer<Dictionary<string, TimestampedRequest<BookingRequest>>>(dictionaryRepresentation: DictionaryRepresentation.Document,
keySerializer: new StringSerializer(BsonType.String),
valueSerializer: BsonSerializer.SerializerRegistry.GetSerializer<TimestampedRequest<BookingRequest>>());
cm.GetMemberMap(c => c.BookingRequests)
.SetSerializer(customDictionarySerializer);
});
}
我找不到关于必须为public async Task<IEnumerable<DateTime>> GetAllDatesWithUnconfirmedBookings(string restaurant)
{
IEnumerable<DateTime> dates = null;
try
{
dates = await Collection.Find(Builders<DayBookings>.Filter.And(
Builders<DayBookings>.Filter.Eq(d => d.Restaurant, restaurant),
Builders<DayBookings>.Filter.Gte(d => d.Date, DateTime.UtcNow.Date),
Builders<DayBookings>.Filter.ElemMatch(d => d.BookingRequests, b => b.Value.Request.Status == Domain.Requests.BookingStatus.Unconfirmed)))
.SortBy(d => d.Date)
.Project(d => d.Date)
.ToListAsync();
}
catch (Exception ex)
{
Logger.Error(ex, $"Error getting all dates with pending bookings for Restaurant={restaurant}");
}
return dates;
}
字段设置的配置的太多信息,因此在此我将不胜感激。
非常感谢!