mercredi 7 octobre 2015

Python db Not equal Mongo Code not Working?

db.serial_key.find({key: {$ne : "5SNT0V"}})

I check this mongodb code typing , direct in shell. I received out put correctly.But with in my Python(3) , It code not working.

// db.serial_key.find({'key':{ '$ne':str(keys[i-1])}})

I tried lot of ways.But every time only run , if statement. I put above code without 'str' , I receive same result.

    for x in keys:
         i +=1;
         print('key %d  = ' %i ,  keys[i-1])  #out put: key 1  =  3ZOHSH

         # place values in dictionary
         keyrecord_record = {'key':keys[i-1],'b_p_code':x1}


         if(db.serial_key.find({'key':{ '$ne':str(keys[i-1])}})):
             db.insert(keyrecord_record)
         else:
             print('Record in DB')

please , expect some expert help.Now , I try to do this, within one day. I want to write only value , not in databases.

I refer this question too. Mongo db not equal to query not working

but ,not solving my question.

Aucun commentaire:

Enregistrer un commentaire