Have encountered same trouble, to cleanup DBs after tests, and actual answer only confused because of absence "code blocks", so dig docs/code once more, for others-time-saving purpose posting this ;)
Mongoose collection extends Mongodb collection
/*
* section collection.js
* http://mongoosejs.com/docs/api.html#collection-js
*/
interface CollectionBase extends mongodb.Collection {
Documentation : http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html
Same goes for the connection:
The Connection class exposed by require('mongoose')
is actually the driver's NativeConnection class.
connection.js defines a base class that the native
versions extend. See:
http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-connection-js
So all "RAW" operations can be performed on collection/connection,
assuming that you have
var connection = mongoose.connection;
then:
1.drop the database:
connection.dropDatabase()
2.create a collection
connection.collection('newcollection') // creates if not exists
3.write some data to a collection
connection.collection('mybenotnewcollection').bulkWrite([
{ insertOne: { whatewer: { you: 'need' } } },
]);
4.query a collection
that's obviously not a question: findAll, find, aggregate, all allowed (see the Docs)
5.drop a collection
connection.collection('notsonewcollection').drop()