Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  39] [ 5]  / answers: 1 / hits: 18755  / 7 Years ago, mon, may 1, 2017, 12:00:00

I am running this on Node.js version 6.9.5



I have this code:



let {Schema}, mongoose = require('mongoose');


which is in theory a simplified version of:



let mongoose = require('mongoose');
let Schema = mongoose.Schema;


I get this error:



let {Schema}, mongoose = require('mongoose');
^^^^^^^^
SyntaxError: Missing initializer in destructuring declaration


I tried this instead:



let mongoose, {Schema} = require('mongoose');


I got a different error, which was the result of mongoose being undefined.



I thought it was possible to do something like this, what am I doing wrong?


More From » node.js

 Answers
7

No.



let {Schema}, mongoose = require('mongoose');



it's same as



let {Schema};
let mongoose = require('mongoose');`


so it will not work because it's not exists object wherefrom take Schema .



let mongoose, {Schema} = require('mongoose');



it's same as



let mongoose;
let {Schema} = require('mongoose');`


And mongoose is really undefined.


[#57942] Friday, April 28, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daquanmilesw

Total Points: 57
Total Questions: 102
Total Answers: 110

Location: Wallis and Futuna
Member since Sat, Aug 6, 2022
2 Years ago
daquanmilesw questions
;