实体
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace HelloWorldApi.Entities;
public class Deck
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; } = ObjectId.GenerateNewId().ToString();
public string Name { get; set; } = "";
public List<string> Cards { get; set; } = new();
}
public class Credentials
{
public string Username { get; set; } = "";
public string Password { get; set; } = "";
}
[BsonIgnoreExtraElements]
public class Account {
public string Status = "";
public string Type = "";
public Credentials Credentials = new();
}
[BsonIgnoreExtraElements]
public class Player
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; } = "";
public Account Account = new ();
public List<string> Roles { get; set; } = new ();
public List<Deck> Decks { get; set; } = new ();
public List<string> Cards { get; set; } = new ();
}
该服务:
public List<Player> GetUsers()
{
return _players.FindSync<Player>(FilterDefinition<Player>.Empty).ToList();
}
具体来说,我希望包括帐户、凭据、用户名,但不包括密码。
1条答案
按热度按时间bmp9r5qi1#
你需要蒙戈projection
该文档添加了一个示例:
所以你可以这样做