Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么MongoDB将对象数组强制转换为字符串类型?_Javascript_Node.js_Mongodb_Mongoose - Fatal编程技术网

Javascript 为什么MongoDB将对象数组强制转换为字符串类型?

Javascript 为什么MongoDB将对象数组强制转换为字符串类型?,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,我对下面的错误感到非常困惑,因为我觉得它很像 运行猫鼬种子,我有以下模型: 用户模型 const mongoose = require("mongoose") const Schema = mongoose.Schema const userSchema = new Schema({ firstName: String, lastName: String, title: String, email: String, password: String,

我对下面的错误感到非常困惑,因为我觉得它很像

运行猫鼬种子,我有以下模型:

用户模型

const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: String
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const cvSchema = new Schema({
    name: String,
    user: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    userInfo: {
        firstName: String,
        lastName: String,
        title: String,
        email: String,
        password: String,
        phone: String,
        profilePicture: String,
        profileDescription: [{}]


    },
    employment: [{
        title: String,
        employer: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    education: [{
        degree: String,
        school: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    skills: [{
        skill: String,
        level: Number,
    }],
    links: [{
        label: String,
        link: String,
    }],
}, {
    timestamps: true,
})

const CV = mongoose.model("CV", cvSchema)

module.exports = CV
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const descriptionSchema = new Schema({ description: [{}] })

const Description = mongoose.model("descriptionSchema", descriptionSchema)

module.exports = Description
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
CV型号

const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: String
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const cvSchema = new Schema({
    name: String,
    user: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    userInfo: {
        firstName: String,
        lastName: String,
        title: String,
        email: String,
        password: String,
        phone: String,
        profilePicture: String,
        profileDescription: [{}]


    },
    employment: [{
        title: String,
        employer: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    education: [{
        degree: String,
        school: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    skills: [{
        skill: String,
        level: Number,
    }],
    links: [{
        label: String,
        link: String,
    }],
}, {
    timestamps: true,
})

const CV = mongoose.model("CV", cvSchema)

module.exports = CV
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const descriptionSchema = new Schema({ description: [{}] })

const Description = mongoose.model("descriptionSchema", descriptionSchema)

module.exports = Description
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
描述模型

const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: String
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const cvSchema = new Schema({
    name: String,
    user: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    userInfo: {
        firstName: String,
        lastName: String,
        title: String,
        email: String,
        password: String,
        phone: String,
        profilePicture: String,
        profileDescription: [{}]


    },
    employment: [{
        title: String,
        employer: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    education: [{
        degree: String,
        school: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    skills: [{
        skill: String,
        level: Number,
    }],
    links: [{
        label: String,
        link: String,
    }],
}, {
    timestamps: true,
})

const CV = mongoose.model("CV", cvSchema)

module.exports = CV
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const descriptionSchema = new Schema({ description: [{}] })

const Description = mongoose.model("descriptionSchema", descriptionSchema)

module.exports = Description
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
种子

require('dotenv').config()

const mongoose = require('mongoose')
const User = require('../models/user.model')
const CV = require('../models/cv.model')
const Template = require('../models/template.model')
const Description = require('../models/description.model')

mongoose.connect(`mongodb://localhost/${process.env.LOCALDB}`, { useNewUrlParser: true, useUnifiedTopology: true })


const bcrypt = require("bcrypt")
const bcryptSalt = 10
const salt = bcrypt.genSaltSync(bcryptSalt)


const exampleDescription = [
    {
        "type": "paragraph",
        "children":
         [
                     {"text": "This is editable "},
                     {"text": "rich","bold": true},
                     {"text": " text, "},
                     {"text": "much", "italic": true},
                     {"text": " better than a normal text !"}
         ]
    },
    { 
       "type": "paragraph",
       "children":
            [
                {"text": "Since it's rich text, you can do "},
                {"text": "thing", "bold": true},
                {"text": "s like turn a selection of text "},
                {"text": "bold", "bold": true},
            ]
    },
    {
        "type": "paragraph", 
        "children":
            [{"text": "Try it out for yourself!sdjfgndfjgkdfsgjkldsfmg" }]
    },
    {
        "type": "paragraph",
        "children": [{ "text": "" }]
    },
    {
        "type": "bulleted-list",
        "children":
            [
                { "type": "list-item", "children": [{ "text": "dfsgsdfgsdfg" }] },
                { "type": "list-item", "children": [{ "text": "dsfgsdfgsdfgjjj"}]},
                { "type": "list-item", "children": [{ "text": "dfsgsdfgdfsg"}]},
                { "type": "list-item", "children": [{ "text": "dsfg" }] },
                { "type": "list-item", "children": [{ "text": "dsfgsdfg" }]},
                { "type": "list-item", "children": [{ "text": "sdfgsdfg" }]},
                { "type": "list-item", "children": [{ "text": "dsfgsdg" }]},
                { "type": "list-item", "children": [{ "text": "" }] },
                { "type": "list-item", "children": [{ "text": "" }] }]},
                { "type": "paragraph", "children": [{ "text": "sdfgsdfgsdfgsdfg" }] },
                { "type": "paragraph", "children": [{ "text": "dfgdfsg" }] },
                { "type": "paragraph", "children": [{ "text": "" }] }
]

const users = [
    {
        firstName: "Example 1",
        lastName: "Last Name 1",
        title: "Student",
        email: "a@a.com",
        password: bcrypt.hashSync('pass1', salt),
        phone: "123456789",
        profilePicture: "https://qph.fs.quoracdn.net/main-qimg-134e3bf89fff27bf56bdbd04e7dbaedf.webp",
        profileDescription: exampleDescription,
        //profileDescription: { description: exampleDescription },
    },
    {
        firstName: "Demo 1",
        lastName: "Demo 2",
        title: "Yoga Instructor",
        email: "b@b.com",
        password: bcrypt.hashSync('pass2', salt),
        phone: "987654321",
        profilePicture: "https://www.google.com/url?sa=i&url=http%3A%2F%2Fwww.nelsonirrigation.com%2Fmedia%2Fpeople%2F%3FC%3DD%3BO%3DD&psig=AOvVaw2UHc769pta1clyVHKolHF6&ust=1589280988466000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIj2zZvTq-kCFQAAAAAdAAAAABAi",
        profileDescription: exampleDescription
        //profileDescription: { description: exampleDescription }

    },
]

const cvs = []

const createCVs = (user) => {

    cvs.push(
        {
            name: 'Apollo',
            employment: employment,
            education: education,
            skills: skills,
            links: links,
            userInfo: {
                firstName: user.firstName,
                lastName: user.lastName,
                title: user.title,
                email: user.email,
                phone: user.phone,
                profilePicture: user.profilePicture,
                profileDescription: user.profileDescription
            },
            user: user.id
        },
        {
            name: "Poseidon",
            employment: employment,
            education: education,
            skills: skills,
            links: links,
            userInfo: {
                firstName: user.firstName,
                lastName: user.lastName,
                title: user.title,
                email: user.email,
                phone: user.phone,
                profilePicture: user.profilePicture,
                profileDescription: user.profileDescription
            },
            user: user.id
        },
        {
            name: "Hermes",
            employment: employment,
            education: education,
            skills: skills,
            links: links,
            userInfo: {
                firstName: user.firstName,
                lastName: user.lastName,
                title: user.title,
                email: user.email,
                phone: user.phone,
                profilePicture: user.profilePicture,
                profileDescription: user.profileDescription
            },
            user: user.id
        }
    )
}

const employment = [
    {
        title: "Marketing Consultant",
        employer: "Neointec",
        start: "Jan-2019",
        end: "May-2020",
        city: "Alicante",
        description: "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Repellat, dolor alias. Officia architecto facere voluptates ullam dolore magnam inventore obcaecati earum nostrum, odit hic dolores distinctio sunt corrupti delectus modi.",
    },
    {
        title: "Yoga Instructor",
        employer: "Gavin Belson",
        start: "Jan-2019",
        end: "Current",
        city: "Alicante",
        description: "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Repellat, dolor alias. Officia architecto facere voluptates ullam dolore magnam inventore obcaecati earum nostrum, odit hic dolores distinctio sunt corrupti delectus modi.",
    },
]


const education = [
    {
        degree: "Marketing",
        school: "King Juan Carlos University",
        start: "2014",
        end: "2018",
        city: "Madrid",
        description: "Just a description",
    },
    {
        degree: "Webdev",
        school: "IronHack",
        start: "2020",
        end: "2020",
        city: "Madrid",
        description: "Just a description 2",
    },
    {
        degree: "Mindfulness",
        school: "Life",
        start: "2014",
        end: "2018",
        city: "Madrid",
        description: "Just a description 3",
    },
]


const links = [
    {label: "Prject 1",link: "https://theuselessweb.com/"},
    {label: "Project 2",link: "https://heeeeeeeey.com/"}
]


const templates = [
    {name: "Apollo"},
    {name: "Hermes"},
    {name: "Poseidon"},
    {name: "Zeus"},
    {ame: "Aphodite"},


]

const skills = [
    {skill: "Node.js",level: 2},
    {skill: "JS",level: 3},
    {skill: "React",level: 3},
]

User.create(users)
    .then(allUsers => allUsers.forEach(user => createCVs(user)))
    .then(() => CV.create(cvs))
    .then(() => Template.create(templates))
    .then(() => Description.create({ description: exampleDescription }))
    .then(() => mongoose.connection.close()})
    .catch(error => console.log(error))
如您所见,user.profileDescription属性与描述模型完全相同(我这样做是有意的:我不打算使用描述模型)

当我运行seed时,描述模型工作得非常好:它创建了一个包含所有存储信息的单个对象,但是,关于CV模型,我得到了以下强制转换错误:

Error [ValidationError]: User validation failed: profileDescription: Cast to string failed for value "[
  {
    type: 'paragraph',
    children: [ [Object], [Object], [Object], [Object], [Object] ]
  },
  {
    type: 'paragraph',
    children: [ [Object], [Object], [Object], [Object], [Object] ]
  },
  { type: 'paragraph', children: [ [Object] ] },
  { type: 'paragraph', children: [ [Object] ] },
  {
    type: 'bulleted-list',
    children: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ]
  },
  { type: 'paragraph', children: [ [Object] ] },
  { type: 'paragraph', children: [ [Object] ] },
  { type: 'paragraph', children: [ [Object] ] }
]" at path "profileDescription"
    at ValidationError.inspect {
  errors: {
    profileDescription: MongooseError [CastError]: Cast to string failed for value "[
      {
        type: 'paragraph',
        children: [ [Object], [Object], [Object], [Object], [Object] ]
      },
      {
        type: 'paragraph',
        children: [ [Object], [Object], [Object], [Object], [Object] ]
      },
      { type: 'paragraph', children: [ [Object] ] },
      { type: 'paragraph', children: [ [Object] ] },
      {
        type: 'bulleted-list',
        children: [
          [Object], [Object],
          [Object], [Object],
          [Object], [Object],
          [Object], [Object],
          [Object]
        ]
      },
      { type: 'paragraph', children: [ [Object] ] },
      { type: 'paragraph', children: [ [Object] ] },
      { type: 'paragraph', children: [ [Object] ] }
    ]" at path "profileDescription"
        at new CastError {
      stringValue: '"[\n' +
        '  {\n' +
        "    type: 'paragraph',\n" +
        '    children: [ [Object], [Object], [Object], [Object], [Object] ]\n' +
        '  },\n' +
        '  {\n' +
        "    type: 'paragraph',\n" +
        '    children: [ [Object], [Object], [Object], [Object], [Object] ]\n' +
        '  },\n' +
        "  { type: 'paragraph', children: [ [Object] ] },\n" +
        "  { type: 'paragraph', children: [ [Object] ] },\n" +
        '  {\n' +
        "    type: 'bulleted-list',\n" +
        '    children: [\n' +
        '      [Object], [Object],\n' +
        '      [Object], [Object],\n' +
        '      [Object], [Object],\n' +
        '      [Object], [Object],\n' +
        '      [Object]\n' +
        '    ]\n' +
        '  },\n' +
        "  { type: 'paragraph', children: [ [Object] ] },\n" +
        "  { type: 'paragraph', children: [ [Object] ] },\n" +
        "  { type: 'paragraph', children: [ [Object] ] }\n" +
        ']"',
      kind: 'string',
      value: [Array],
      path: 'profileDescription',
      reason: null,
      message: 'Cast to string failed for value "[\n' +
        '  {\n' +
        "    type: 'paragraph',\n" +
        '    children: [ [Object], [Object], [Object], [Object], [Object] ]\n' +
        '  },\n' +
        '  {\n' +
        "    type: 'paragraph',\n" +
        '    children: [ [Object], [Object], [Object], [Object], [Object] ]\n' +
        '  },\n' +
        "  { type: 'paragraph', children: [ [Object] ] },\n" +
        "  { type: 'paragraph', children: [ [Object] ] },\n" +
        '  {\n' +
        "    type: 'bulleted-list',\n" +
        '    children: [\n' +
        '      [Object], [Object],\n' +
        '      [Object], [Object],\n' +
        '      [Object], [Object],\n' +
        '      [Object], [Object],\n' +
        '      [Object]\n' +
        '    ]\n' +
        '  },\n' +
        "  { type: 'paragraph', children: [ [Object] ] },\n" +
        "  { type: 'paragraph', children: [ [Object] ] },\n" +
        "  { type: 'paragraph', children: [ [Object] ] }\n" +
        ']" at path "profileDescription"',
      name: 'CastError'
    }
  },
  _message: 'User validation failed',
  name: 'ValidationError'
}

我不明白为什么它指出了一个字符串转换错误,因为我正在为
user.profileDescription

说真的,我们非常感谢您的帮助

事先非常感谢

编辑

幸亏我发现了错误:用户模型接受的是字符串而不是对象数组[{}]

将此问题标记为已解决

谢谢大家

解决方案:

用户模型

const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: String
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const cvSchema = new Schema({
    name: String,
    user: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    userInfo: {
        firstName: String,
        lastName: String,
        title: String,
        email: String,
        password: String,
        phone: String,
        profilePicture: String,
        profileDescription: [{}]


    },
    employment: [{
        title: String,
        employer: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    education: [{
        degree: String,
        school: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    skills: [{
        skill: String,
        level: Number,
    }],
    links: [{
        label: String,
        link: String,
    }],
}, {
    timestamps: true,
})

const CV = mongoose.model("CV", cvSchema)

module.exports = CV
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const descriptionSchema = new Schema({ description: [{}] })

const Description = mongoose.model("descriptionSchema", descriptionSchema)

module.exports = Description
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User

在cv模式中,您有
profileDescription:[{}]

所以
profileDescription
应该是一个对象数组,但是您传递了一个对象
{description:exampleDescription}

我看到您之前传递了一个字符串,但是

因此,您需要直接传递数组
exampleDescription

const users = [
    {
        firstName: "Example 1",
        lastName: "Last Name 1",
        title: "Student",
        email: "a@a.com",
        password: bcrypt.hashSync('pass1', salt),
        phone: "123456789",
        profilePicture: "https://qph.fs.quoracdn.net/main-qimg-134e3bf89fff27bf56bdbd04e7dbaedf.webp",
        //profileDescription: "Experienced and dedicated Federal Government HR Manager with over ten years of experience, ensure HR systems support agencies in recruiting, hiring and retaining an excellent and diverse workforce. Adept at providing optimal support to executives and officials in need. Committed to integrity and constantly securing the privacy of identities and documents. Bringing forth a proven track record of facilitating excellent workflow in HR departments.",
        profileDescription: exampleDescription, pass the array directly
    },
    {
        firstName: "Demo 1",
        lastName: "Demo 2",
        title: "Yoga Instructor",
        email: "b@b.com",
        password: bcrypt.hashSync('pass2', salt),
        phone: "987654321",
        profilePicture: "https://www.google.com/url?sa=i&url=http%3A%2F%2Fwww.nelsonirrigation.com%2Fmedia%2Fpeople%2F%3FC%3DD%3BO%3DD&psig=AOvVaw2UHc769pta1clyVHKolHF6&ust=1589280988466000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIj2zZvTq-kCFQAAAAAdAAAAABAi",
        //profileDescription: "Experienced and passionate Yoga Instructor with over five years of teaching experience and advanced training in Ashtanga and Vinyasa approaches. Committed to providing extensive instruction and counseling to my clients, while motivating them to find true inner peace and their healthiest self. Adept in creating powerful teaching plans that aim to support and benefit each and every student. Bringing forth a love and respect for the art of yoga, and all that it encompasses. "
        profileDescription: exampleDescription, // pass the array directly

    },
]
希望有帮助,因为我发现了错误:用户模型接受的是
字符串,而不是
对象[{}]
数组

将此问题标记为已解决

多谢各位

解决方案:

用户模型

const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: String
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const cvSchema = new Schema({
    name: String,
    user: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    userInfo: {
        firstName: String,
        lastName: String,
        title: String,
        email: String,
        password: String,
        phone: String,
        profilePicture: String,
        profileDescription: [{}]


    },
    employment: [{
        title: String,
        employer: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    education: [{
        degree: String,
        school: String,
        start: String,
        end: String,
        city: String,
        description: String,
    }],
    skills: [{
        skill: String,
        level: Number,
    }],
    links: [{
        label: String,
        link: String,
    }],
}, {
    timestamps: true,
})

const CV = mongoose.model("CV", cvSchema)

module.exports = CV
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const descriptionSchema = new Schema({ description: [{}] })

const Description = mongoose.model("descriptionSchema", descriptionSchema)

module.exports = Description
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User
const mongoose = require("mongoose")
const Schema = mongoose.Schema

const userSchema = new Schema({
    firstName: String,
    lastName: String,
    title: String,
    email: String,
    password: String,
    phone: String,
    profilePicture: String,
    profileDescription: [{}]
}, {
    timestamps: true
})

const User = mongoose.model("User", userSchema)

module.exports = User

关键是终端错误,正如所指出的:
用户验证失败
,这导致用户模型修订和以下错误发现。

嗨,穆罕默德,首先,感谢您的回答。不幸的是,我也尝试过这个,但我一直都会遇到同样的错误。感谢您指出:我将旧代码传递到问题中,但我所做的上一次测试确实是直接传递数组,仍然不起作用。@Togeri如果问题的代码不正确,您能更正它吗?不确定到底要哪种类型,对象数组还是object@TheeSritabtim我已经改正了,抱歉给你带来了困惑,抱歉。尽管如此,代码还是得到了相同的错误。如果用户架构是问题所在,请将用户架构作为well@TheeSritabtim用户模式已包含在第一个代码中,标记为“用户模型”。您的用户模型有一个带有
mongoose.Model(“CV”,cvSchema)
,,所以实际上是CV模型错误显示用户验证失败,所以我想我们应该看看那里。绝对是:那是Begging的错误。现在看起来很琐碎,但我发现它的时候真的很糟糕。非常感谢您的帮助@TheeSritabtim