0

i have this query and it is working in MongoDB Booster, but i don't understand why i can't only copy this in Python, as i do for query on MySQL, and what should I do with this query, so it can work normally in MongoDB

Query that works in MongoDB Booster but it doesn't work when i copy in Python looks like this:

db.bol_rac.aggregate( [
  {
    $project:
      {
        "id" : 1,
        "id_drz": 1,    
        "location" :
        {          
             $cond: { if: { $eq: [ "$id_drzavljanstvo", 688 ] }, then: "Country", else: "Foreign country" }          
         }
      }
   }
] );
1
  • Please show exactly how you tried to run this in Python. Commented Oct 14, 2017 at 16:43

1 Answer 1

1

i mean on this, i have success to solve the problem, problem is that i haven't add '' on if,else,then ..

  from pymongo import MongoClient
    client = MongoClient()

    db = client.bol_rac

    cursor = db.bol_rac.aggregate([
      {
        '$project':
          {
            'id' : 1,
            'id_drz': 1,    
            'location' :
            {          
                 '$cond': { 'if': { '$eq': [ '$id_drz', 688 ] }, 'then': 'Country', 'else': 'Foreign country' }          
             }
          }
       }
    ])

    for document in cursor:
        print(document)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.