I have a document like this
{
'_id': '3c7df42e91c611e7bf575ce0c5482b4b',
'authors': ['Bruno Rocha'],
'authors_slug': ['bruno-rocha'],
'category': 'python/flask',
'date': datetime.datetime(2017, 9, 4, 20, 10, 26),
'published': True,
'slug': 'simple-login-extension-for-flask',
'tags': ['python', 'flask', 'pythonplanet', 'pyplanet', 'new'],
'title': 'Simple Login Extension for Flask',
}
It has a 'tags': ['python', 'flask', 'pythonplanet', 'pyplanet', 'new'] and I have more documents with tag python
When I search using {'tags': 'python'}
col.find({'tags': 'python'}).count()
25.09 22:19:22 tinymongo.tinymongo DEBUG query to parse2: {'tags': 'python'}
25.09 22:19:22 tinymongo.tinymongo DEBUG query: {'tags': 'python'} prev_query: None
25.09 22:19:22 tinymongo.tinymongo DEBUG conditions: tags python
25.09 22:19:22 tinymongo.tinymongo DEBUG c: QueryImpl('==', ('tags',), 'python')
25.09 22:19:22 tinymongo.tinymongo DEBUG new query item2: QueryImpl('==', ('tags',), 'python')
0
Ok that is expected so lets use {'$in': 'python'}
col.find({'tags': {'$in': 'python'}}).count()
25.09 22:20:34 tinymongo.tinymongo DEBUG query to parse2: {'tags': {'$in': 'python'}}
25.09 22:20:34 tinymongo.tinymongo DEBUG query: {'tags': {'$in': 'python'}} prev_query: None
25.09 22:20:34 tinymongo.tinymongo DEBUG conditions: tags {'$in': 'python'}
25.09 22:20:34 tinymongo.tinymongo DEBUG c: None
25.09 22:20:34 tinymongo.tinymongo DEBUG query: {'$in': 'python'} prev_query: tags
25.09 22:20:34 tinymongo.tinymongo DEBUG conditions: $in python
25.09 22:20:34 tinymongo.tinymongo DEBUG c: None
25.09 22:20:34 tinymongo.tinymongo DEBUG new query item2: None
0
or with a list: {'$in': ['python', 'flask']}
col.find({'tags': {'$in': ['python', 'flask']}}).count()
25.09 22:21:09 tinymongo.tinymongo DEBUG query to parse2: {'tags': {'$in': ['python', 'flask']}}
25.09 22:21:09 tinymongo.tinymongo DEBUG query: {'tags': {'$in': ['python', 'flask']}} prev_query: None
25.09 22:21:09 tinymongo.tinymongo DEBUG conditions: tags {'$in': ['python', 'flask']}
25.09 22:21:09 tinymongo.tinymongo DEBUG c: None
25.09 22:21:09 tinymongo.tinymongo DEBUG query: {'$in': ['python', 'flask']} prev_query: tags
25.09 22:21:09 tinymongo.tinymongo DEBUG conditions: $in ['python', 'flask']
25.09 22:21:09 tinymongo.tinymongo DEBUG c: None
25.09 22:21:09 tinymongo.tinymongo DEBUG query: {'tags': 'python'} prev_query: None
25.09 22:21:09 tinymongo.tinymongo DEBUG conditions: tags python
25.09 22:21:09 tinymongo.tinymongo DEBUG c: QueryImpl('==', ('tags',), 'python')
25.09 22:21:09 tinymongo.tinymongo DEBUG query: {'tags': 'flask'} prev_query: None
25.09 22:21:09 tinymongo.tinymongo DEBUG conditions: tags flask
25.09 22:21:09 tinymongo.tinymongo DEBUG c: QueryImpl('==', ('tags',), 'flask')
25.09 22:21:09 tinymongo.tinymongo DEBUG new query item2: QueryImpl('or', frozenset({('==', ('tags',), 'python'), ('==', ('tags',), 'flask')}))
0
I checked the source code and currently the $in operator only works in the reverse way, it works currently to match a single field against an array of possibilities. But not to check an array against a single value or array.
I have a document like this
{ '_id': '3c7df42e91c611e7bf575ce0c5482b4b', 'authors': ['Bruno Rocha'], 'authors_slug': ['bruno-rocha'], 'category': 'python/flask', 'date': datetime.datetime(2017, 9, 4, 20, 10, 26), 'published': True, 'slug': 'simple-login-extension-for-flask', 'tags': ['python', 'flask', 'pythonplanet', 'pyplanet', 'new'], 'title': 'Simple Login Extension for Flask', }It has a
'tags': ['python', 'flask', 'pythonplanet', 'pyplanet', 'new']and I have more documents with tagpythonWhen I search using
{'tags': 'python'}Ok that is expected so lets use
{'$in': 'python'}or with a list:
{'$in': ['python', 'flask']}I checked the source code and currently the
$inoperator only works in thereverseway, it works currently to match a single field against an array of possibilities. But not to check an array against a single value or array.