I am using aggregation with mongoDB, now I am facing a problem, I am trying to match my documents that are present in my input array using the $ in operator. Now I want to know that the lement index from the input array can someone now tell me how I can do this.
My code
var coupon_ids = ["58455a5c1f65d363bd5d2600", "58455a5c1f65d363bd5d2601","58455a5c1f65d363bd5d2602"] couponmodel.aggregate( { $match : { '_id': { $in : coupons_ids }} }, function(err, docs) { if (err) { } else { } });
Coupon module diagram
var CouponSchema = new Schema({ category: {type: String}, coupon_name: {type: String},
UPDATE - As user3124885 suggested, aggregation is not better in performance, can someone tell me the performance difference between aggregation and regular query in mongodb. And which one is better?
Update - I read this question on SO mongodb-aggregation-match-vs-find-speed . Here the user himself commented that both of them take the same time, also seeing vlad-z answer, I think aggregation is better. Please, if any of you worked for mongodb Then please tell me what you think about it.
UPDATE - I used json data samples containing 30,000 rows and tried to match with v / s aggregation. Query aggregation detection was performed in 180 ms, where the search query took 220 ms. In addition, I ran $ lookup, it also took no more than 500 ms, so data aggregation is faster than a regular request. Please correct me guys, if any of you tried to use aggregation, and if not, why not?
UPDATE -
I read this post where the user uses the code below as a replacement for $ zip SERVER-20163 , but I do not understand how I can solve my problem using the code below. So can someone please tell me how can I use the code below to solve my problem.
{$map: { input: { elt1: "$array1", elt2: "$array2" }, in: ["$elt1", "$elt2"] }
Now someone can help me, it would be very nice for me.