在 mongodb 中查找没有光标的条目?
我使用 mongodb 和 java。有一个功能登录,该功能正在检查数据库中的邮件和适合的密码。如果没有则返回 false,如果有则返回 true:
boolean login(String email, String password) {
/**/
BasicDBObject query = new BasicDBObject();
query.put("email", email);
query.put("password", password);
DBCollection collection = c.getDatabase().getCollection("...");
DBCursor cursor = collection.find(query);
if (cursor.size() > 0)
return true;
return false;
}
我感觉这个函数看起来很丑^^ 有没有更好的方法在 java 中编写这个代码?避免古鲁?嗯,它的工作原理,但可能有更好的方法,如 cursor.size()
谢谢
Im using mongodb and java. There is a function login, this function is checking the db for a mail and fit password. If there is no one then return false, if yes then true:
boolean login(String email, String password) {
/**/
BasicDBObject query = new BasicDBObject();
query.put("email", email);
query.put("password", password);
DBCollection collection = c.getDatabase().getCollection("...");
DBCursor cursor = collection.find(query);
if (cursor.size() > 0)
return true;
return false;
}
I have the feeling that this function looks ugly ^^ Is there a better way to code this in java? Avoid a curos? Well its working but there could be a better way as cursor.size()
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道它在 Java 中是如何工作的,但是,findOne() 方法应该返回单个文档,如果没有这样的文档,则返回 null。
I don't know how it works in Java, however, the findOne() method should return a single document or null if there is no such document.