比较两个数组的相似值javascript

时间:2016-04-01 06:51:07

标签: javascript arrays node.js mongodb

我有两个数组,一个来自表单请求,另一个来自mongoDb查询。我想查找在mongodb数组中获得的结果中的请求参数中传递的所有项目。

    var userIdArr = ["6fbeb3e28de42200e7e7d36", "56fbde9be618221c1d67f01"];
    var mongoDbResultsArr= [
          {"_id": "56fce5bf7031bd482abdfb8a",
         "userIds": "[56fbeb3e28de42200e7e7d36, 56fbde9be618221c1d67f010]"
          },
          {"_id": "56fd2c22ea0f3664156685ac",
          "userIds": "[56fbeb3e28de42200e7e7d36, 56fbde9be618221c1d67f010, 56f53491886e496e32c68b00]"
              }
            ]

基本上我想搜索userIdArr中给出的值是否存在于< userIds' mongoDbResultsArr的关键。如果这可以通过编写mongodb查询或任何其他更好的方式来完成。

这就是我的架构的样子

{
"_id" : ObjectId("56fd2c22ea0f3664156685ac"),
"startDateTime" : ISODate("2016-03-31T08:34:59.000Z"),
"endDateTime" : ISODate("2016-03-31T08:34:59.000Z"),
"productId" : "#789990#2",
"applicableThemes" : [ 
    "red"
],
"userIds" : "[56fbeb3e28de42200e7e7d36, 56fbde9be618221c1d67f010, 56f53491886e496e32c68b00]",
"price" : 45,
"dealType" : 1,
"photos" : {
    "dealimageUrl3" : "http://mailers.shopping.indiatimes.com/shopstatic/shopping/images/diwali2013/banner.jpg",
    "dealimageUrl2" : "http://mailers.shopping.indiatimes.com/shopstatic/shopping/images/diwali2013/banner.jpg",
    "dealimageUrl1" : "http://mailers.shopping.indiatimes.com/shopstatic/shopping/images/diwali2013/banner.jpg"
},
"dealDescription" : "Bang Bang deal!!",
"dealName" : "Christmas Special Offer",
"storeId" : "56f5339fe99b1a294818ecbe",
"__v" : 0

}

我正在使用猫鼬ORM。

0 个答案:

没有答案