finding document with array property
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior and if the current behavior is a bug, please provide the steps to reproduce.** Given that we have a document in mongodb as shown below,
{
_id: ObjectID("5d8d3fdb563f2001b5559242"),
prop: ["va1", "val2", "val3"]
}
Executing the query mymodel.find({ prop: ["val1", "val3"]
returns the above document (but it shouldn’t).
What is the expected behavior? According to the mongodb official page, this should not return the above document. Unless the array of the query exactly matches the array of the document, it should not return as a matched document.
I’ve run the exact same query on the mongodb shell and it worked as expected, so I can only conclude that mongoose is the culprit.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version. Mongoose: 5.6.11 (latest) Node.js: 12.10.0 MongoDB: 3.4.20
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8
Thank you @vkarpov15 for the detailed answer! 😃
My apologies. I just looked into Typegoose docs and I found out that I was misusing the
prop
decorator when, in fact, I was supposed to usearrayProp
.I will leave the issue opened in case @BenSower needs to clarify a few things with the collaborators before it is closed.
@BenSower I appreciate the response since I could drill down what was causing this and also learned about the casting behaviour in Mongoose with arrays.