File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-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 @@ -13927,6 +13927,29 @@ describe('document', function() {
1392713927 await savedDoc . save ( ) ;
1392813928 } ) ;
1392913929
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+ } ,
13940+ {
13941+ toObject : { flattenObjectIds : true }
13942+ }
13943+ ) ;
13944+ const Test = db . model ( 'Test' , TestSchema ) ;
13945+
13946+ const professionalId = new mongoose . Types . ObjectId ( ) ;
13947+ await Test . insertMany ( [ { professionalId, firstName : 'test' } ] ) ;
13948+
13949+ const doc = await Test . findOne ( { professionalId } ) . lean ( ) . orFail ( ) ;
13950+ assert . ok ( doc . professionalId instanceof mongoose . Types . ObjectId ) ;
13951+ } ) ;
13952+
1393013953 it ( 'handles buffers stored as EJSON POJO (gh-14911)' , async function ( ) {
1393113954 const pdfSchema = new mongoose . Schema ( {
1393213955 pdfSettings : {
You can’t perform that action at this time.
0 commit comments