MongoDB Learning Notes Aggregation pipeline practical implementation INNER JOIN

Source: Internet
Author: User

Aggregation pipeline to achieve inner join:

LEFTT Collection:

Comments Collection:

Now we're going to implement inner join with aggregation.

Db.comments.aggregate ([{$lookup: {from:"LEFTT", Localfield:"timestamp", Foreignfield:" Timestamp "" Timestampcol"" $timestampCol "},{$project: {" Ratingeq ": {" $eq ": [" $rating "," $ Timestampcol.rating "]}," timestamp ": 1," rating ": 1,  " Timestampcol.timestamp ": 1}},{$match: {" Ratingeq " :true}}])

Isn't it amazing?

Step parsing:

    1. $lookup: Implements timestamp equivalent connection, equal LEFTT result is placed in Timestampcol collection
    2. $unwind: Implemented to flatten the LEFTT array, there are multiple
    3. $project: Implementation of the second equivalent connection rating, and placed in the Ratingeq field
    4. $match: Take only Ratingeq is true, indicating that the second rating field is equal

MongoDB Learning Note Aggregation Pipeline actual combat implementation inner JOIN

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.