gpt4 book ai didi

javascript - "msg":"Error parsing JSON field value. 意外的 OBJECT_START

转载 作者:太空宇宙 更新时间:2023-11-03 22:29:41 24 4
gpt4 key购买 nike

我正在使用 Node 和 Mongoose 来更新沃森排名和检索数据库。我正在尝试将文档添加到集合中。我可以添加一个文档。但是,我为多个创建的 json 对象失败了。我在这里看到了这个答案,但它是针对 curl 的。我想知道是否有人可以帮助我完成 JS 部分。

    // add a document
//var doc = { id : 1234, title_t : 'Hello', text_field_s: 'some text' };
var data = [];

for (var count = 0; count < documents.length ; count++){
data.push({"add":{"doc":{id : documents[count]._id, problem : documents[count].problem, description : documents[count].description, resolution : documents[count].resolution}}})
}

console.log(data);

solrClient.add(data, function(err) {
if(err) {
console.log('Error indexing document: ' + err);
} else {
console.log('Indexed a document.');
solrClient.commit(function(err) {
if(err) {
console.log('Error committing change: ' + err);
} else {
console.log('Successfully commited changes.');
callback(documents);
}
});
}
});

我明白了:

[ { add: { doc: [Object] } },
{ add: { doc: [Object] } },
{ add: { doc: [Object] } },
{ add: { doc: [Object] } },
{ add: { doc: [Object] } },
{ add: { doc: [Object] } } ]

但是,我想我需要这个:[ 添加:{doc:[对象] },添加:{doc:[对象]},...

当我尝试删除添加前面的 { 时,出现错误(参数列表后缺少 ),并且它不会运行。

最佳答案

查看the test code ,我认为您需要使用一个简单的文档对象数组:

var data = [];

for (var count = 0; count < documents.length ; count++){
data.push({ id : documents[count]._id, problem : documents[count].problem, description : documents[count].description, resolution : documents[count].resolution})
}

关于javascript - "msg":"Error parsing JSON field value. 意外的 OBJECT_START,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39251400/

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