Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

using $lookup from array of a document in mongodb

I have two schemas A and B

A has structure like

{
    _id:"5ff4c9862a1c24022aed7899",
    steps:[
        {id:"5ff149596e5e2358e5af007f",name:"step1"},
        {id:"5fedc8560eca62001142c89b",name:"step2"},
    ]
}

B has structure like

{
    _id:"5ff2e7928b597bc948a23c14",
    steps_id:"5ff149596e5e2358e5af007f",
    A_id:"5ff4c9862a1c24022aed7899"
}

I want to use aggregate query to get B with appropriate step_id.

One thing I did was use $lookup and then use subsequent pipeline to match and get my step but I was wondering if there a more elegant way of doing it


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...