gpt4 book ai didi

javascript - 更新 : Unable to invalidate a subdocument that has not been added to an array

转载 作者:搜寻专家 更新时间:2023-11-01 00:00:56 24 4
gpt4 key购买 nike

我在 mongoose 中有一个 upsert 查询,它在 3.8 中运行,但是在我升级到 4 之后,我得到了

Unable to invalidate a subdocument that has not been added to an array

这是我的模型:

var ActivitySchema = new Schema({
owner:{
type: Schema.Types.ObjectId,
ref: 'User'
},
sequence:{
type:Number,
default: 0
},
items:[
{
posted:{
type:Date,
default:Date.now
},
verb:{
type: String,
enum: [ 'leave','join','support','share','comment', 'upload', 'rate','message','update', 'signup']
},
text:{
type: String,
},
reference: {
objectType:{
type: String,
enum: [ 'document','element','process', 'project', 'user']
},
refObj:{}
}
}]
});

更新插入:

Activity.update({
$and:[
{'owner':ownerId},
{'sequence':bucket}
]},
{
$push:{items:newItem }
},
{
upsert:true
}).execAsync();

数据是这样的:

//newItem
{ verb: 'join',
text: 'Has joined to a team',
reference:
{
refObj: { teamId: '56269fd1e923cc7a7b46dcf8', name: 'test1' },
objectType: 'user'
}
}

ownerId 是一个 mongoId,例如 56251c01507dc35423694118bucket是一个整数0

是否有任何我需要注意的重大变化?我一直在寻找但尚未找到相关的任何其他解决方法、解决方案?

最佳答案

我遇到过同样的问题,如果情况相同,请确保所有字段类型都与 mongoose.model('yourModel') 匹配。希望有所帮助。

关于javascript - 更新 : Unable to invalidate a subdocument that has not been added to an array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33271196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com