我有这样的查询
db.Usage.find({'Usage': "",'Rating': "", 'Average Ratings': ""}).count()
1500
我想删除此查询的最后500个条目。他们是一种删除最后500个条目的方法,或者我必须立即删除与该查询匹配的所有文档,然后再次插入有效的1000个文档
提前致谢
答案 0 :(得分:1)
it = db.Usage.find({'Usage': "",'Rating': "", 'Average Ratings': ""})[1001:1500]
to_rem = []
for doc in iter:
to_rem.append( doc['_id'] )
try:
db.Usage.remove( {'_id' :{ '$in': to_rem } })
except:
print "Unexpected error:", sys.exc_info()[0]