我找不到任何关于使用新的PHP库创建新的MogoId istance的参考。使用遗留驱动程序,您可以使用var param = { "email": "ex.ample@email.com" };
$.ajax({
url: "/api/users/" + param.email,
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data == true) {
// notify user that email exists
}
else {
// not taken
}
}
});
[HttpGet, Route("api/users/{emailaddress}")]
public bool Get(string emailaddress)
{
string email = emailaddress;
UserStore<ApplicationUser> userStore = new UserStore<ApplicationUser>();
ApplicationUserManager<ApplicationUser> manager = new ApplicationUserManager<ApplicationUser>(userStore);
ApplicationUser user = manager.FindByEmail(email);
if (user != null)
{
return true;
}
else
{
return false;
}
}
//helper class:
public class UserResponse
{
public string email { get; set; }
}
但是对于新的php库,此类不存在。
答案 0 :(得分:5)
经过一些挖掘驱动程序源后,它被调用如下:
new \MongoDB\BSON\ObjectID($id);