question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

finding document with array property

See original GitHub issue

Do 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
BenSowercommented, Oct 14, 2019

Thank you @vkarpov15 for the detailed answer! 😃

1reaction
hwkdcommented, Oct 6, 2019

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 use arrayProp.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query an Array of Embedded Documents — MongoDB Manual
This page provides examples of query operations on an array of nested documents using the db.collection.find() method in mongosh . The examples on...
Read more >
Find document with array that contains a specific value
In case you need to find documents which contain NULL elements inside an array of sub-documents, I've found this query which works pretty...
Read more >
How to search in array of object in MongoDB? - Tutorialspoint
To search the array of object in MongoDB, you can use $elemMatch operator. This operator allows us to search for more than one...
Read more >
How to Find & Filter MongoDB Array Elements Using ...
In this tutorial, we are going to learn how to select only those documents in our dataset that contain fields within arrays that...
Read more >
MongoDb: Project an element's property inside an array in a ...
Related Query · MongoDb: Project an element's property inside an array in a document with conditions · find any document which holds in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found