简体   繁体   中英

How to use AND condtion in mongokit when a key has multiple values

I have a key in my document named "tag". Now this has the structure like this:

"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"
    }
  ],

the values of tag can be passed ',' separated. How can i use those values in a AND condition saying return the enrty having tag = test_tag3&test_tag2

Itried it like this : conditions['tag.slug'] = { '$and': tags } where tags is array of tags but i got :

pymongo.errors.OperationFailure

OperationFailure: database error: invalid operator: $and

使用$in代替$and

conditions['tag.slug'] = { '$in': tags }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM