Working with subdocuments

The Difference between a Sub document and an Embedded Field

db.books.find("author.lastname": "Steinbeck") // Embedded Field

I am searching for a field embedded within a sub document and that’s going to return one record for me
Embedded field search for properties inside of sub documents

While the sub document searches for anything that matches exactly the past and sub document

db.books.find({author: {firstname: "John", lastname: "Steinbeck"})

this is actually searching by the sub document and it means the entire sub document, but it should match exactly, it means the value and order they have to appear in the same order

Reference

Mongoose 101
Mongoose 101: Working with subdocuments
Mongoose 101: Population

Leave a Reply

Your email address will not be published. Required fields are marked *