如何返回 MongoDB 数组的单个元素?
我想返回 Mongodb 数组的单个元素。我从表单中获取用户名和密码,并使用 findOne() 函数来验证它在数据库中是否存在。
$user = $collection->findOne(array(
'username' => $username,
'password' => $password,
));
在它返回的数组中还有一个邮政编码。我想将数组的该元素存储在一个变量中,以便将其与另一个变量连接起来。
I would like to return a single element of a Mongodb array. I am taking a username and password from a form and using the findOne()
function to verify it's existence in the database.
$user = $collection->findOne(array(
'username' => $username,
'password' => $password,
));
In the array that it returns there is also a zip code. I would like to store that element of the array in a variable to concatenate it with another variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要返回所有这些信息。据我了解,您所需要的只是一个密码,因此您的查询应该是这样的
;
$user['pincode'] 将是您需要的密码。
第二个数组确保您不会收到除 pincode 之外的任何附加且不重要的信息
You don't need an to return all this information. As I understood all you need is a pincode, so your query should be this way
;
$user['pincode'] will be a pincode you need.
the second array ensure that you will not receive any additional and unimportant information except of pincode