Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export custom data from object #165

Closed
sandip-jadhav opened this issue Mar 1, 2018 · 3 comments
Closed

Export custom data from object #165

sandip-jadhav opened this issue Mar 1, 2018 · 3 comments
Assignees

Comments

@sandip-jadhav
Copy link

sandip-jadhav commented Mar 1, 2018

{ "_id": "d4ebc3b9397ba3faaacde2bfb80089e7", "_rev": "2-69b7ea5b6dd7495ff3d26a0fc5630825", "personal": { "firstName": "Dan", "lastName": "Denney", "dob": "12/26/87", "gender": "male" }, "work": { "workTitle": "Software Engineer", "workCompany": "Code School" }, "social": { "website": "dandenney.com", "emailId": "[email protected]", "twitter": "dandenney1", "facebook": "dandenney" }, "address": { "houseNumber": "52", "streetName": "main street", "city": "lodz", "country": "poland" } }

Want to export simple object with attributes firstName, lastName & company
We created transform.js
// example transformation function // -- remove leading and trailing quotes var x = function(doc) { doc.firstName = doc.personal.firstName; doc.lastName= doc.personal.lastName; doc.company = doc.work.workCompany; delete doc.work; delete doc.social; delete doc.address; return doc; } module.exports = x;

Command used
couchexport --url https://localhost:5984 --database tomtomdemo --delimiter "," --transform "D:\Places\optimus\Tools\couchDbTools\transform.js" > test_1.csv

Result : not expected
_id,personal,work,social,address
d4ebc3b9397ba3faaacde2bfb80089e7,[object Object],[object Object],[object Object],[object Object]

@glynnbird
Copy link
Owner

Your transform function leaves an object behind:

{ _id: 'd4ebc3b9397ba3faaacde2bfb80089e7',
  _rev: '2-69b7ea5b6dd7495ff3d26a0fc5630825',
  personal: 
   { firstName: 'Dan',
     lastName: 'Denney',
     dob: '12/26/87',
     gender: 'male' },
  firstName: 'Dan',
  lastName: 'Denney',
  company: 'Code School' }

Try delete doc.personal in your transform function?

@sandip-jadhav
Copy link
Author

sandip-jadhav commented Mar 1, 2018

@glynnbird Thank you for instant reply

Updated transform function by adding delete doc.personal
//Get simple attribute from nested object var x = function(doc) { doc.firstName = doc.personal.firstName; doc.lastName= doc.personal.lastName; doc.company = doc.work.workCompany; delete doc.work; delete doc.social; delete doc.address; delete doc.personal; return doc; } module.exports = x;

Same result
_id,personal,work,social,address
d4ebc3b9397ba3faaacde2bfb80089e7,[object Object],[object Object],[object Object],[object Object]

@glynnbird
Copy link
Owner

Actually @sandip-jadhav I know what's happening here. The transform step is only used on couchimport not on couchexport but actually what you have suggested here is a reasonable use-case, so I'll have a go (tomorrow) to implement transformation on the export process too.

I'll use this issue to track progress.

@glynnbird glynnbird self-assigned this Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants