我这样问是因为当我编写单元测试时,我想删除测试数据库,插入一些初始化数据,并在测试中判断mongodb中的数据.所以我需要对mongodb进行原始操作.
如何在mongoose 身上做到这一点?我现在能做的就是创建连接,而不是在mongoose的官方网站上找到任何文档.
var mongoose = require('mongoose');
mongoose.connect('mongo://localhost/shuzu_test');
// get the connection
var conn = mongoose.connection;
但如何:
- 删除数据库
- 创建一个集合
- 向集合中写入一些数据
- 查询集合
- 放弃Collection