I want to add array in getting response in mongodb response (data fetching from mongo)
{ _id: 23232385,
CompanyId: 232385,
CompanyCd: 'MONDLAY',
CompanyName: 'Company Name ',
Competition: false,
ParentCompany: 707,
CareOf: '',
AddressLine2: '',
AddressLine3: '',
Suite: '',
City: 'Los Angeles',
StateCd: 'CA',
Zip: '90010',
Title: '',
Phone: '549-334',
Extension: '',
Fax: '549-9834',
Comment: '',
Abrev: '',
Email: '[email protected]' }
And want this response in JSON below like format.
[
{ _id: 23232385,
CompanyId: 232385,
CompanyCd: 'MONDLAY',
CompanyName: 'Company Name ',
Competition: false,
ParentCompany: 707,
CareOf: '',
AddressLine2: '',
AddressLine3: '',
Suite: '',
City: 'Los Angeles',
StateCd: 'CA',
Zip: '90010',
Title: '',
Phone: '549-334',
Extension: '',
Fax: '549-9834',
Comment: '',
Abrev: '',
Email: '[email protected]' }
]
Also want something which goes with function. Also trying to implement the same thing with huge data set. Can anyone help me with this?
Thanks in advance
collection.find().each(function(err, item, response, status) { console.log(item) Array.from(item).forEach(itemdata => { bulk.push({index:{ _index: esIndexName, _type: mongoCollectionName, } }) bulk.push(itemdata) })here I'm trying to convertitemadding object array @SaurabhAgrawal