为什么即使在删除集合后mongo仍在获取结果?

时间:2014-09-10 08:40:43

标签: mongodb mongoengine

使用pymongo我删除了一个特定的集合。当我使用mongoengine查询数据库时,x.objects.get(y ="某些东西")仍然显示已删除的结果。

任何人都请帮助我...提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用drop方法:

from pymongo import Connection
connection = Connection('localhost', 27017) #Connect to mongodb

print(connection.database_names())  #Return a list of db, equal to: > show dbs

db = connection['testdb1']          #equal to: > use testdb1
print(db.collection_names())        #Return a list of collections in 'testdb1'
print("posts" in db.collection_names())     #Check if collection "posts" 
                                            #  exists in db (testdb1)

collection = db['coll']
print(collection.count() == 0)    #Check if collection named 'coll' is empty

collection.drop()                 #Delete (drop) collection named 'coll' from db