Szymon Roziewski
Szymon Roziewski

Reputation: 1133

How to search through a nested field which is a list in MongoDB

I would like to search for a pattern, for each element in a list, which is a nested field in MongoDB. I have an Object, which contains authors list, which can contain from 0 to N elements. I want to retrieve objects whose authors met the search pattern. An author contains 4 fields, I only scan for names and surnames. How to do that within MongoDB query?

enter image description here

Upvotes: 0

Views: 59

Answers (1)

JavierC
JavierC

Reputation: 26

You could use a query like:

db.article.find({$and:[{"authors.givenNames":"javier"},{"authors.familyName":"XXXXX"}]})

You can read about it in This link

Hope it helps you!

Upvotes: 1

Related Questions