0

I have the below code to return all blogs where the blog author ID is equal to the ID of the first administrator (orgAdmin) in an array:

let officialBlogs = await Blog.find().where('author.id').equals(help.orgAdmins[0]);

But I can't work out how to adapt this code so I can return blogs where the author matches ANY of the administrators in the array (i.e. orgAdmin[0], orgAdmin[1], orgAdmin[2] etc. Can anyone please advise?

1

1 Answer 1

2

You can use $in operator to get things based on passed ids like this:

const ids = [];
help.orgAdmins.forEach(id => ids.push(id));

let officialBlogs = await Blog.find({author.id: { $in: ids }});
Sign up to request clarification or add additional context in comments.

2 Comments

we can pass help.orgAdmins directly right? instead of 'ids'
Yes, you can do that too if they are always fixed or same numbers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.