I have a method that, thanks to Twython, saves the tweets to MongoDB as it is in my question Maintaining a mongodb with tweets that match a given tag
def getSearchTagTwitter(hashtag):
db = connexMongoDB()
t = loginTwython()
search = t.search(q=hashtag, count=100)
data = search['statuses']
try:
db.twittersearch.create_index('id_str')
for tweet in data:
try :
db.twittersearch.insert_one(tweet)
except :
db.twittersearch.update_one({"id_str": tweet['id_str']}, tweet)
except Exception:
print "Error al buscar hashtag"
time.sleep(60*15) #15 minutos
getSearchTagTwitter(hashtag)
I think it's not working correctly and I want to check if the value of id_str
is not echoed through the MongoDB shell and/or from Python. I've tried the following but it doesn't give me any results:
db.twittersearch.find({'id_str':{$in:["numerodeid_str"]}})
Edit: I simplify the question. From Python, how could I check if I don't have duplicates in a mongodb already created? I'm currently connecting with pymongo, and I can see that I've created the collection.