Python 当一个键有多个值时,如何在mongokit中使用和条件
我的文档中有一个名为“tag”的密钥。现在它的结构是这样的:Python 当一个键有多个值时,如何在mongokit中使用和条件,python,mongodb,pymongo,mongokit,Python,Mongodb,Pymongo,Mongokit,我的文档中有一个名为“tag”的密钥。现在它的结构是这样的: "tag": [ { "schemeName": "http:\/\/somesite.com\/categoryscheme2", "name": "Test Tag2", "value": 1, "slug": "test_tag2" }, { "schemaName": "http:\/\/somesite.com\/categoryscheme
"tag": [
{
"schemeName": "http:\/\/somesite.com\/categoryscheme2",
"name": "Test Tag2",
"value": 1,
"slug": "test_tag2"
},
{
"schemaName": "http:\/\/somesite.com\/categoryscheme3",
"name": "Test Tag3",
"value": 1,
"slug": "test_tag3"
}
],
标记的值可以通过“,”分隔传递。
我如何在返回enrty having tag=test_tag3&test_tag2的条件中使用这些值
我这样做:conditions['tag.slug']={'$and':tags}
其中tags
是标签数组,但我得到:
pymongo.errors.OperationFailure
OperationFailure: database error: invalid operator: $and
在中使用
$而不是$和
:
conditions['tag.slug'] = { '$in': tags }