【问题标题】:$push is not working in mongoDB$push 在 mongoDB 中不起作用
【发布时间】:2018-10-14 13:28:06
【问题描述】:

我想要一个这样的数据结构——

collegeName: { type: String, default: null }, semesters: [ { name : { type: String, default: null }, professors : [], students : [] } ], pictureURL: { type: String, default: null }, time: { type : Date, default: Date.now }

这就是我定义我的猫鼬模式的方式。

但现在我正在尝试像这样更新学期数组 -

await NewCollege.findOneAndUpdate(
        {
            collegeName : college
        },
        {
            $push: {
                "semesters": { name : "college", professors : ["prof A", "prof B"], students : ["Student A", "Student B", "Student C"]},
            }
        },
        {
            new : true
        },
    )
    .then((result) => {
        dataToSendBack = result
    })
    .catch((err) => {
        return h.response(err)
    })

但是当我从邮递员发帖时,我没有得到想要的结果,它会引发错误。请有人告诉我我做错了什么。

【问题讨论】:

  • 你能把邮递员的错误贴出来吗?
  • @MạnhQuyếtNguyễn 请检查我刚刚发布的答案。它包含错误图像。
  • 如果你有服务器日志/应用程序错误日志应该会更好

标签: mongodb mongoose mongoose-schema


【解决方案1】:

你发布了完整的代码吗?

collegeNamestring 所以我认为正确的条件是:

{collegeName: "college"}

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 2016-02-26
    • 2018-04-27
    • 2017-06-30
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 2013-05-10
    • 2018-02-08
    • 2017-01-16
    相关资源
    最近更新 更多