gpt4 book ai didi

javascript - meteor 。 MongoDB upsert错误: TypeError: keypath. split不是函数。 (在 'keypath.split(' .')' 中, 'keypath.split' 未定义)

转载 作者:行者123 更新时间:2023-12-03 06:09:24 24 4
gpt4 key购买 nike

Foo 是我的 MongoDB 集合。我只有一个文档:

{
0: {code: "basic", caption: "basic", points: 100},
1: {code: "gold", caption: "gold", points: 200},
2: {code: "platinum", caption: "platinum", points: 300},
3: {code: "diamond", caption: "diamond", points: 400},
id: "PnpbhFi8m7NqZXRr6"
}

当我尝试更新插入时,我收到以下错误:

TypeError: keypath.split is not a function. (In 'keypath.split('.')', 'keypath.split' is undefined)

这是我的代码:

const data = [
{
"code": "basic",
"caption": "basic",
"points": 100
},
{
"code": "gold",
"caption": "gold",
"points": 200
},
{
"code": "platinum",
"caption": "platinum",
"points": 300
},
{
"code": "diamond",
"caption": "diamond",
"points": 400
}
];

const doc = Foo.findOne();
Foo.upsert(doc._id, { $set: data });

我的错误在哪里?

最佳答案

你使用了$set错误。您必须将对象传递给 $set:

Foo.update(doc._id, {
$set: {
4: data[0],
5: data[1],
6: data[2],
7: data[3],
}
});

此外,您不必使用upsert。来自 meteor docs关于更新插入:

Modify one or more documents in the collection, or insert one if no matching documents were found

但是你的文档存在,所以不需要upsert,使用update

关于javascript - meteor 。 MongoDB upsert错误: TypeError: keypath. split不是函数。 (在 'keypath.split(' .')' 中, 'keypath.split' 未定义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39387548/

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