语法错误:意外令牌,应为(10:10)

时间:2018-09-18 16:12:36

标签: javascript reactjs

我正在与此一起练习JavaScript代码。 https://rationalappdev.com/api-backend-with-nodejs-express-and-mongodb-for-react-native-apps/

我试图用自己的代码更改数据库部分,但是当我在终端上运行此代码时, enter image description here

发生此错误。

,这是 baby.js 的代码。

    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);

1 个答案:

答案 0 :(得分:3)

您只能在对象中使用:来分配值,而不能在数组中使用。因此,您需要将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 }
    }]
  });

如果属性faces不应该是数组,则只需删除[]对象周围的roi