I'm trying to query for a user which has an array within an array. I can get the mongo shell command working fine, although the node.js command won't work, just showing "found user" without a user object concatenated.
Shell (working):
db.users.find(
{
"username":"gregpmillr",
"completed_modules": {
"$elemMatch": {
"module": {
"$elemMatch": {
"module_id":ObjectId("59a0d98e9df98d39e0760faf")
}
}
}
}
}
).pretty()
Node.js (no returned user):
User.find(
{
"username":username,
"completed_modules": [{
"module": [{
"module_id": module_id
}]
}]
}
)
.exec()
.then(user => {
if (user) {
console.log("found user: " + user);
} else {
console.log("no matched user");
}
})
Where User is a model, username is logged in user, module_id is simply the _id for another collection.
Probably something small that I'm missing. I tried to follow Node.js driver docs as much as I could but couldn't really find the answer since I don't believe $elemMatch works with the driver.
Any ideas?