尝试将对象加载到MongoDB数据库中。但它没有得到“拯救”。
var collection = DatabaseHelper.Database.GetCollection<UserDTO>("Users");
UserDTO newUser = new UserDTO();
newUser.LastLogin = DateTime.Now;
newUser.LastLogout = newUser.LastLogin;
newUser.Password = password;
newUser.PhoneNumber = "";
newUser.UserName = userName;
await collection.InsertOneAsync(newUser);
然后我运行&#34; db.Users.count()&#34;返回0.如果我在C#中使用Find,它也不返回任何记录。
我的UserDTO对象是:
public class UserDTO
{
[MongoDB.Bson.Serialization.Attributes.BsonId()]
public ObjectId Id { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string PhoneNumber { get; set; }
public DateTime LastLogin { get; set; }
public DateTime LastLogout { get; set; }
public Token CurrentSecurityToken { get; set; }
}