我正在尝试从我的 MongoDB 数据库中的集合中返回单个值,但是我得到了一个返回的空值,并且集合中存在具有该 id 的文档。
public async Task<Business> GetBusiness(string businessId)
{
var objectId = new ObjectId(businessId);
var filter = Builders<Business>.Filter.Eq("_id", objectId);
var entity = await _businessMongoCollection.Find(filter).FirstAsync();
return entity;
}
我也试过这样做,但我得到一个空结果。
var filter = Builders<Business>.Filter.Eq("_id", new ObjectId(businessId));
var foundBusinessTask = await _businessMongoCollection.FindAsync(filter);
var foundBusiness = await foundBusinessTask.SingleOrDefaultAsync();