【发布时间】:2020-06-17 19:03:36
【问题描述】:
我想进行一个查询,现在我将在其中提供一个 _id 和国家名称,结果我想找到给定国家/地区是否存在于这三个数组中的真值或假值。如果存在则 true 而不是 false。例如我有 country:France 和 _id:5e4d18bd10e5482eb623c6e4 那么结果将是-
country_array_1:真, country_array_2:真, country_array_3:false
我想要一个 mongo db 查询这种类型的输入和输出我可以聚合或 findOne 但我想要我的答案
0 _id:5e4d18bd10e5482eb623c6e4
country_array_1:['France','Italy','China'],
country_array_2:['Finland','England','France']
country_array_3:['USA','turkey','India']
1 _id:5e4345bd10e5482eb62E4X11f
country_array_1:['Srilanka','Malaysia','Pakistan'],
country_array_2:['Egypt','Austria','Netherland']
country_array_3:['Mexico','turkey','India']
我想进行一个查询,我将在其中输入
[Input]
_id:5e4d18bd10e5482eb623c6e4,
country:'France'
[Output]
country_array_1:true,
country_array_2:true,
country_array_3:false
【问题讨论】:
-
看看mongo聚合管道,你肯定可以做到的。
-
我已经查看并尝试过,但我没有得到准确的答案,是的,您是正确的,答案将通过聚合来实现,但是如何?
标签: node.js mongodb mongoose mongoose-schema