Merge pull request #11892 from simonxca/patch-mongoose

Mongoose fixes ObjectId constructor
This commit is contained in:
Horiuchi_H
2016-10-11 16:51:57 +09:00
committed by GitHub
2 changed files with 17 additions and 4 deletions
+1
View File
@@ -525,6 +525,7 @@ mongoose.Types.Buffer.from([1, 2, 3]);
*/
var objectId: mongoose.Types.ObjectId = mongoose.Types.ObjectId.createFromHexString('0x1234');
objectId = new mongoose.Types.ObjectId(12345);
objectId = mongoose.Types.ObjectId(12345);
objectId.getTimestamp();
/* practical examples */
export interface IManagerSchema extends mongoose.MongooseDocument {
+16 -4
View File
@@ -1091,10 +1091,22 @@ declare module "mongoose" {
}
/*
* section types/objectid.js
* http://mongoosejs.com/docs/api.html#types-objectid-js
*/
class ObjectId extends mongodb.ObjectID {}
* section types/objectid.js
* http://mongoosejs.com/docs/api.html#types-objectid-js
*/
var ObjectId: ObjectIdConstructor;
// mongodb.ObjectID does not allow mongoose.Types.ObjectId(id). This is
// commonly used in mongoose and is found in an example in the docs:
// http://mongoosejs.com/docs/api.html#aggregate_Aggregate
// constructor exposes static methods of mongodb.ObjectID and ObjectId(id)
type ObjectIdConstructor = typeof mongodb.ObjectID & {
(s?: string | number): mongodb.ObjectID;
}
// var objectId: mongoose.Types.ObjectId should reference mongodb.ObjectID not
// the ObjectIdConstructor, so we add the interface below
interface ObjectId extends mongodb.ObjectID {}
/*
* section types/embedded.js