mongokit 从集合中删除所有项目
我想从测试集合中删除所有项目。我的设置是
connection = Connection(app.config['MONGODB_HOST'], app.config['MONGODB_PORT'])
db = connection.test_database.tutorial
我有一个映射到测试集合的文档模型类 Test。我尝试使用两者删除集合
connection.test_database.drop_collection('tutorial.tests')
db.tests.remove()
但是查询类似的内容
list(db.Test.find())
仍然给我旧数据。类似
list(db.tests.find())
返回一个空列表。但是,如果我在测试中添加新条目,以前的查询也不会反映更改,所以我认为这也不准确。
I would like to remove all items from a test collection. My setup is
connection = Connection(app.config['MONGODB_HOST'], app.config['MONGODB_PORT'])
db = connection.test_database.tutorial
I have a document model class Test which maps to the tests collection. I've tried deleting the collection with both
connection.test_database.drop_collection('tutorial.tests')
db.tests.remove()
However querying something like
list(db.Test.find())
still gives me the old data. Something like
list(db.tests.find())
returns an empty list. However if I add new entries into tests the previous query also doesn't reflect the changes, so I don't think thats accurate either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在这一行:
db = 连接.test_database.tutorial
因为它说测试数据库和教程集合
删除工作,当我将其更改为
db = 连接.教程
Problem was with this line:
db = connection.test_database.tutorial
Since it was saying test database and the tutorial collection
removing worked when I changed it to
db = connection.tutorial