0

I have a db object looking like this:

{
   user_name: 'string',
   skills: [ 
       { skill: 'skill1', lvl: 3 } 
   ],
   wantsToLearn: [ 
       {skill: 'skill2' } 
   ]
}

I want to make a query wherein I find all users with a wantToLearn skill matching with one pf my input user's skill (regardless of lvl) AND vice versa. Basically, I want to be able to find all users with a match between a skill and something they want to learn.

I have looked at the mongodb documentation and am still a bit clueless on how to do this the best way. I am new to databases in general except for some sql.

Any pointers would be very appreciated!

1

1 Answer 1

1

If you want to find all users matching your given skill, all you have to do is :

db.getCollection('yourCollection').find({"wantsToLearn.skill": "skill2" })

That's the way you query subdocuments in MongoDB, even in arrays

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.