SyntaxError: Unexpected token, expected , (10:10)
SyntaxError: Unexpected token, expected , (10:10)
I'm practicing JavaScript code with this. https://rationalappdev.com/api-backend-with-nodejs-express-and-mongodb-for-react-native-apps/
I'm trying to change DB part with my own code, but when I run this at the terminal, 
this error occurs.
and this is baby.js's code.
import mongoose, Schema from 'mongoose';
var babySchema = new Schema(
info:
size:
width: number, height: number ,
faceCount: number
,
faces:
[ roi :
x: number, y: number, width: number, height: number ,
landmark:
leftEye: x: number, y: number ,
rightEye: x: number, y: number ,
nose: x: number, y: number ,
leftMouth: x: number, y: number ,
rightMouth: x: number, y: number ,
gender: value: String, confidence: number ,
age: value: String, confidence: number ,
emotion: value: String, confidence: number ,
pose: value: String, confidence: number
]
);
export default mongoose.mode('baby', babySchema);
faces: [ .. ]
faces ...
is an array. there are no associative arrays in js, you probably want an object: – Xatenev
Sep 18 '18 at 16:15
1 Answer
1
You can use the : only in objects to assign a value and not in an array. So you need to wrap roi: ... in roi: :
:
roi: ...
roi:
var babySchema = new Schema(
info:
size:
width: number, height: number ,
faceCount: number
,
faces:
[ roi :
x: number, y: number, width: number, height: number ,
landmark:
leftEye: x: number, y: number ,
rightEye: x: number, y: number ,
nose: x: number, y: number ,
leftMouth: x: number, y: number ,
rightMouth: x: number, y: number ,
gender: value: String, confidence: number ,
age: value: String, confidence: number ,
emotion: value: String, confidence: number ,
pose: value: String, confidence: number
]
);
If the attribute faces should not be an array, just remove the around the roi object.
faces
roi
That's also possible, but I don't know, if he wants an array of faces or not
– Batajus
Sep 18 '18 at 16:22
Thanks! it works. 😂
– Jinne
Sep 18 '18 at 16:52
@jinne if worked then mark response as answer
– Er. Amit Joshi
Sep 18 '18 at 18:14
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
Try changing
faces: [ .. ]tofaces ...– dustytrash
Sep 18 '18 at 16:14