From bf99493e116329b2cc8f2ed4a898467b328bcf29 Mon Sep 17 00:00:00 2001 From: simonxca Date: Wed, 29 Nov 2017 22:13:11 -0800 Subject: [PATCH] Allow overriding id attribute --- types/mongoose/index.d.ts | 2 +- types/mongoose/mongoose-tests.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index f86dea4f8a..311d2d298f 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -1144,7 +1144,7 @@ declare module "mongoose" { interface MongooseDocumentOptionals { /** The string version of this documents _id. */ - id?: string; + id?: any; } interface DocumentToObjectOptions { diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index 9fe20cd8ad..57c98fcbbf 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -503,6 +503,25 @@ doc.populate(cb); doc.populate({path: 'hello'}).execPopulate().catch(cb); doc.update({$inc: {wheels:1}}, { w: 1 }, cb); +const ImageSchema = new mongoose.Schema({ + name: {type: String, required: true}, + id: {type: Number, unique: true, required: true, index: true}, +}, { id: false }); + +interface ImageDoc extends mongoose.Document { + name: string, + id: number +} + +const ImageModel = mongoose.model('image', ImageSchema); + +ImageModel.findOne({}, function(err, doc) { + if (doc) { + doc.name; + doc.id; + } +}); + /* * section types/subdocument.js * http://mongoosejs.com/docs/api.html#types-subdocument-js @@ -1277,6 +1296,7 @@ mongoModel.remove(function (err, product) { if (err) throw(err); MongoModel.findById(product._id, function (err, product) { if (product) { + product.id.toLowerCase(); product.remove(); } });