Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$elemMatch returns all subjects #80

Closed
Miscellaneous opened this issue Oct 16, 2018 · 1 comment
Closed

$elemMatch returns all subjects #80

Miscellaneous opened this issue Oct 16, 2018 · 1 comment

Comments

@Miscellaneous
Copy link

Not sure where the issues arise from, but

e.g In a document I have stored an array with 100 card objects, I only desire to pull one card with id:20 from that document

From console 3.6, this do exactly that:
db.myCards.findOne({ user_id: x }, { cards: { $elemMatch: { id: 20 }}} );

But, from latest hapi-mongo-models, same line will return all cards in the array

@Miscellaneous
Copy link
Author

Solved: use "fields" ...

db.myCards.findOne({ user_id: x }, { fields: { cards: { $elemMatch: { id: 20 }}}});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants