EFB/Mongo/Mongo.cs

30 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Bson;
using EFB.Models;
namespace EFB.MongoData
{
public class Mongo
{
//function that is responsible to getting the user's latest sim position from the MongoDB
public static async Task<SimPositionModel> GetLatestData(string email){
MongoClient client = new MongoClient(
Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User)
);
MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");
FilterDefinition<SimPositionModel> filter = Builders<SimPositionModel>.Filter.Eq(x => x.EMail, email);
var data = await collection.FindAsync<SimPositionModel>(filter).Result.ToListAsync();
if (data.Count > 0)
{
return data[0];
}
return null;
}
}
}