0

I have a list of "usernames" as an array, and a list of posts in a mongodb collection with an "author" variable. I want to get all objects from the collection whose author is one of the usernames in the array.

so if:

Collection: { "author": "tim" }, { "author": "bob" }, { "author": "jon" }

following = ["tim", "jon"]

then i only want to get the posts by tim and jon

1 Answers1

0

I got the answer; it should be:

following = ["tim", "jon"]
mongo.db.posts.find({"author": {"$in": following}})

This will only get posts where the author is tim or jon.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77