Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly enabling versionKey throws exception #3747

Closed
sebastian-nowak opened this issue Jan 11, 2016 · 1 comment
Closed

Explicitly enabling versionKey throws exception #3747

sebastian-nowak opened this issue Jan 11, 2016 · 1 comment
Milestone

Comments

@sebastian-nowak
Copy link

Mongoose throws exception when versionKey is explicitly set to true. It assumes it's a new name for the version key.

new mongoose.Schema({
...
}, { versionKey: true });

And here's the exception:

TypeError: Invalid `path`. Must be either string or array                                                                                                                                                
    at Object.exports.set (/tmp/TestProject/node_modules/mpath/lib/index.js:97:11)                                                                                                            
    at Object.exports.setValue (/tmp/TestProject/node_modules/mongoose/lib/utils.js:600:9)                                                                                                    
    at model.Document.setValue (/tmp/TestProject/node_modules/mongoose/lib/document.js:788:9)                                                                                                 
    at model.Model.$__version (/tmp/TestProject/node_modules/mongoose/lib/model.js:578:19)                                                                                                    
    at model.Model.$__handleSave (/tmp/TestProject/node_modules/mongoose/lib/model.js:129:10)                                                                                                 
    at model.Model.$__save (/tmp/TestProject/node_modules/mongoose/lib/model.js:189:9)                                                                                                        
    at /tmp/TestProject/node_modules/mongoose/lib/model.js:288:11                                                                                                                             
    at new Promise.ES6 (/tmp/TestProject/node_modules/mongoose/lib/promise.js:45:3)                                                                                                           
    at model.Model.save (/tmp/TestProject/node_modules/mongoose/lib/model.js:287:10)                                                                                                          
    at model._done (/tmp/TestProject/node_modules/hooks-fixed/hooks.js:101:24)                                                                                                                
    at _next (/tmp/TestProject/node_modules/hooks-fixed/hooks.js:64:28)                                                                                                                       
    at fnWrapper (/tmp/TestProject/node_modules/hooks-fixed/hooks.js:186:18)                                                                                                                  
    at model.Object.defineProperty.value.fn (/tmp/TestProject/node_modules/mongoose/lib/schema.js:250:9)                                                                                      
    at _next (/tmp/TestProject/node_modules/hooks-fixed/hooks.js:62:30)                                                                                                                       
    at fnWrapper (/tmp/TestProject/node_modules/hooks-fixed/hooks.js:186:18)                                                                                                                  
    at /tmp/TestProject/node_modules/mongoose/lib/schema.js:234:13

The docs aren't really clear about the versionKey property and only mention that setting it to false disables versioning, but in my opinion, the above behavior is completely counterintuitive.

@vkarpov15 vkarpov15 added this to the 4.3.6 milestone Jan 11, 2016
@vkarpov15
Copy link
Collaborator

The docs will now specify that versionKey expects a string, and treats 'false' as a special case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants