erlexec icon indicating copy to clipboard operation
erlexec copied to clipboard

How to find by list?

Open Pathos14489 opened this issue 3 years ago • 3 comments
trafficstars

So to explain my situation, I have a document array of documents where every document has a list under the tags attribute called TAGS which is a list of strings.

r = doc_array.find({'tags__TAGS': {'$in': 'test'}})

^Gives me TypeError: 'in <string>' requires string as left operand, not list

r = doc_array.find({'tags__TAGS': {'$in': ["test"]}})

^Results in zero results even on queries I know should have results. I've tried both of these ways to query just for one tag to be in the array(even though I want to query for a whole list of tags to be present in the end, but I can figure that out if someone can help me figure this part out), and for each of them I get errors.

I've also looked into how this is done on Mongo to be sure I was following the correct example since there's not exactly a lot of information about this in the documentation, but that led nowhere.

r = doc_array.find({'tags__TAGS': 'test'})

ValueError: Not a valid query. It should follow the format: { <field1>: { <operator1>: <value1> }, ... } I feel like I'm just being dense and missing something obvious, but I also feel like I've tried everything that makes sense to me.

How am I supposed to be doing this? Does $in actually mean that the field has to be a single value that's checked against an array value? If so, is there like... a $contains or something that isn't documented?

Pathos14489 avatar Jul 08 '22 18:07 Pathos14489