Mongodb 来自find()的意外结果
伙计们,我收集了一些像这样的文件Mongodb 来自find()的意外结果,mongodb,Mongodb,伙计们,我收集了一些像这样的文件 > db.patient.find().pretty() { "_id" : ObjectId("5e1f5165da4c015b2bdacedc"), "firstname" : "max", "lastname" : "schwarzmullar", "age" : "29", "history" : [ {
> db.patient.find().pretty()
{
"_id" : ObjectId("5e1f5165da4c015b2bdacedc"),
"firstname" : "max",
"lastname" : "schwarzmullar",
"age" : "29",
"history" : [
{
"disease" : "cold",
"treatment" : "cataflam"
},
{
"disease" : "inflamation",
"treatment" : "augmenten"
}
]
}
{
"_id" : ObjectId("5e1f5353da4c015b2bdacedd"),
"firstname" : "3abas",
"lastname" : "hamada",
"age" : "25",
"history" : [
{
"disease" : "ich",
"treatment" : "cataflam"
},
{
"disease" : "inflamation",
"treatment" : "augmenten"
}
]
}
{
"_id" : ObjectId("5e1f535eda4c015b2bdacede"),
"firstname" : "falkasa",
"lastname" : "elsokary",
"age" : 39,
"history" : {
"disease" : "exhaustion",
"treatment" : "panadol"
}
}
但是,当我试图搜索任何年龄大于25岁的文档时,它只会给我一份文档,尽管如上所述,您会看到两份具有上述标准的文档,请澄清或更正我
> db.patient.find({age :{$gt:25}}).pretty()
{
"_id" : ObjectId("5e1f535eda4c015b2bdacede"),
"firstname" : "falkasa",
"lastname" : "elsokary",
"age" : 39,
"history" : {
"disease" : "exhaustion",
"treatment" : "panadol"
}
}
> db.patient.find({age :{$gt:25}}).pretty()
在您的收藏中有
“年龄”:“29”,“年龄”:“25”
所以现在25和29是字符串,只需编辑收藏中的年龄即可
年龄:29岁,年龄:25岁
好的,对于某些文档,您的年龄似乎是一个字符串&您的查询有一个数字
{age:{$gt:25}
,类型应该匹配,因为您返回39
是因为number
与number
匹配-所以条件确实适用于这些文档!!您是否仍然需要帮助才能使用相同的数据完成此操作,或者您是否正在更新您的收藏,使其具有所有年龄的int
?非常感谢,我已将其更新为数字和itworked@MohamadMostafa如果您觉得答案有帮助,请将其标记为已接受答案。看见