Each record in the collection has two key “ip” and “timestamp”
db.posts.update({'ip' : '127.0.0.1', 'timestamp' : {'$gt' : sometimestamp}}, {'$set' : {'timestamp' : time.time()}, True)
The command above will insert a new record, if field “ip” with “127.0.0.1” not in the collection or “timestamp” is less than sometimestamp
Now, if I want to insert a new record only “ip” with “127.0.0.1” not in collection, in other word, keep value of “ip” unique.
How to do ?
What you are probably trying to do is this:
So essentially, you are having two different types of updates..One is going to acutally make a change in timestamp and other tells mongo to do nothing, i.e., not even make an insert.
I am guessing this is not possible with an upsert. So better use simple updates as follows:
And I don’t know how you’d write it in Pymongo, but logically speaking, you do this:
Unfortunately, I can’t comment on the performance..