From 382b31d6db27104179aa4bfdc7bc06d78ffbdd42 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 20 Jul 2016 08:29:33 -0400 Subject: [PATCH] modifies mongoose Collection to inherit from mongodb.collection interface --- mongoose/mongoose-tests.ts | 12 ++++++++++-- mongoose/mongoose.d.ts | 28 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts index 55249d5248..f6253bab1a 100644 --- a/mongoose/mongoose-tests.ts +++ b/mongoose/mongoose-tests.ts @@ -101,9 +101,15 @@ coll1.getIndexes(); coll1.collectionName; coll1.conn; coll1.name; -coll1.insureIndex(); +coll1.ensureIndex(); coll1.find({}); -coll1.insert({}, {}, {}); +coll1.insert({}, {}); + +var coll2 = new mongoose.Collection('', new mongoose.Connection(null)); +coll2.$format(999).toLowerCase(); +/* inherited properties */ +coll2.initializeOrderedBulkOp; +coll2.indexExists; /* * section connection.js @@ -1232,6 +1238,8 @@ MongoModel.where('age').gte(21).lte(65).where('name', /^b/i); new (mongoModel.base.model(''))(); mongoModel.baseModelName.toLowerCase(); mongoModel.collection.$format(99); +mongoModel.collection.initializeOrderedBulkOp; +mongoModel.collection.findOne; mongoModel.db.openSet(''); mongoModel.discriminators; mongoModel.modelName.toLowerCase(); diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index 890928f772..44e81b4835 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -127,7 +127,7 @@ declare module "mongoose" { /* Class constructors */ static Aggregate: typeof _mongoose.Aggregate; static CastError: typeof _mongoose.CastError; - static Collection: typeof _mongoose.Collection; + static Collection: _mongoose.Collection; static Connection: typeof _mongoose.Connection; static Document: typeof _mongoose.Document; static DocumentProvider: any; @@ -508,7 +508,8 @@ declare module "mongoose" { * section drivers/node-mongodb-native/collection.js * http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-collection-js */ - class Collection extends CollectionBase { + interface Collection extends CollectionBase { + new(name: string, conn: Connection, opts?: Object): Collection; /** Formatter for debug print args */ $format(arg: any): string; /** Debug print helper */ @@ -2569,7 +2570,7 @@ declare module "mongoose" { * section collection.js * http://mongoosejs.com/docs/api.html#collection-js */ - abstract class CollectionBase { + interface CollectionBase extends mongodb.Collection { /** * Abstract Collection constructor * This is the base class that drivers inherit from and implement. @@ -2577,18 +2578,21 @@ declare module "mongoose" { * @param conn A MongooseConnection instance * @param opts optional collection options */ - constructor(name: string, conn: Connection, opts: Object); + constructor(name: string, conn: Connection, opts?: Object); - /* abstract methods */ - insureIndex(...args: any[]): any; - find(...args: any[]): any; + /* + * Abstract methods. Some of these are already defined on the + * mongodb.Collection interface so they've been commented out. + */ + ensureIndex(...args: any[]): any; + //find(...args: any[]): any; findAndModify(...args: any[]): any; - findOne(...args: any[]): any; + //findOne(...args: any[]): any; getIndexes(...args: any[]): any; - insert(...args: any[]): any; - mapReduce(...args: any[]): any; - save(...args: any[]): any; - update(...args: any[]): any; + //insert(...args: any[]): any; + //mapReduce(...args: any[]): any; + //save(...args: any[]): any; + //update(...args: any[]): any; /** The collection name */ collectionName: string;