File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -75,8 +75,7 @@ const subclassedSymbol = Symbol('mongoose#Model#subclassed');
7575const { VERSION_INC , VERSION_WHERE , VERSION_ALL } = Document ;
7676
7777const saveToObjectOptions = Object . assign ( { } , internalToObjectOptions , {
78- bson : true ,
79- flattenObjectIds : false
78+ bson : true
8079} ) ;
8180
8281/**
Original file line number Diff line number Diff line change @@ -12,5 +12,6 @@ exports.internalToObjectOptions = {
1212 depopulate : true ,
1313 flattenDecimals : false ,
1414 useProjection : false ,
15- versionKey : true
15+ versionKey : true ,
16+ flattenObjectIds : false
1617} ;
Original file line number Diff line number Diff line change @@ -13926,6 +13926,32 @@ describe('document', function() {
1392613926 cur . subdocs [ 0 ] = { test : 'updated' } ;
1392713927 await savedDoc . save ( ) ;
1392813928 } ) ;
13929+
13930+ it ( 'avoids flattening objectids on insertMany (gh-14935)' , async function ( ) {
13931+ const TestSchema = new Schema (
13932+ {
13933+ professionalId : {
13934+ type : Schema . Types . ObjectId
13935+ } ,
13936+ firstName : {
13937+ type : String
13938+ } ,
13939+ nested : {
13940+ test : String
13941+ }
13942+ } ,
13943+ {
13944+ toObject : { flattenObjectIds : true }
13945+ }
13946+ ) ;
13947+ const Test = db . model ( 'Test' , TestSchema ) ;
13948+
13949+ const professionalId = new mongoose . Types . ObjectId ( ) ;
13950+ await Test . insertMany ( [ { professionalId, name : 'test' } ] ) ;
13951+
13952+ const doc = await Test . findOne ( { professionalId } ) . lean ( ) . orFail ( ) ;
13953+ assert . ok ( doc . professionalId instanceof mongoose . Types . ObjectId ) ;
13954+ } ) ;
1392913955} ) ;
1393013956
1393113957describe ( 'Check if instance function that is supplied in schema option is available' , function ( ) {
You can’t perform that action at this time.
0 commit comments