I'm using node and mongoose to update a watson rank and retrieve database. I'm trying to add documents to the collection. I can add a single document. However, the json object I'm creating for multiple is failing. I've seen this answer here, but it was for curl. I was wondering if someone can help me with the JS part.
// 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);
}
});
}
});
I get this:
[ { add: { doc: [Object] } },
{ add: { doc: [Object] } },
{ add: { doc: [Object] } },
{ add: { doc: [Object] } },
{ add: { doc: [Object] } },
{ add: { doc: [Object] } } ]
However, I think I need this: [ add: {doc: [Object] }, add : {doc: [Object] }, ...
When I try to remove the { in front of the add, I get an error (missing ) after argument list) and it won't run.