[英]How to query MongoDB for a value in and array
Can anyone help me with a Mongodb query for following任何人都可以通过 Mongodb 查询来帮助我以获取以下信息
{[
"_id" : ObjectId("5c92ba9d36de59bd9de063a4"),
"StudentName" : "Robert",
"StudentAge" : 21,
"StudentCountryName" : "UK",
"StudentHobby" : [
"Teaching",
"Photography"
]
}
Want to search students with hobby as Teaching .想搜索爱好教学的学生。
If possible can come someone provide Spring Data MongoDB equivalent or native query is also fine which can be executed in mongodb compass如果可能的话,有人可以提供 Spring 数据 MongoDB 等效或本机查询也可以,可以在 mongodb 指南针中执行
You can try this, I hope it work你可以试试这个,希望有用
let student = await this.students.findOne({"StudentHobby":{"$in":["Teaching"]}})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.