I'm trying to get map results and save them into a file.
I'm using this:
fs.writeFileSync(
"id.json",
JSON.stringify(
db.patient.find({},{_id: 1}).map(function(p) { return {id: p._id} })
)
);
I'm getting this error message:
Uncaught:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Topology'
| property 's' -> object with constructor 'Object'
| property 'sessionPool' -> object with constructor 'ServerSessionPool'
--- property 'topology' closes the circle
I've performed inner query alone:
I'm getting this result:
> db.patient.find({},{_id: 1}).map(function(p) { return {id: p._id} });
[
{ id: 'a94271c9-9658-4100-bc4c-9b0d118f3874' },
{ id: '25361e1b-0460-4a37-aaf3-cfe6b1ef4a06' },
{ id: '1affd292-691d-4094-af28-107b899926a6' },
{ id: '04224f3c-dd06-4d22-9783-0c4e93f5cb41' },
{ id: '3c29dbaf-304e-4060-8b80-689159c35d6e' },
{ id: '1af5eadf-86be-43a5-8b3e-73d8420fab15' },
{ id: '6cc9e843-a4b2-43eb-8177-2303a0975973' },
{ id: '0547b28b-3924-4ebd-8106-8ef03eaae8b9' },
{ id: '0539c3c9-be44-4bbb-88eb-66ec201383a7' },
{ id: 'a95ed645-a337-47be-a768-e29d1432daab' },
{ id: 'c6a2ce32-1d4b-4a5d-b778-e886cb4a205c' },
{ id: '063ba0f7-f687-49fd-ae01-23dcfcc7357a' },
{ id: '96a5f896-0ab4-46b8-9c5f-67ffcb82d728' },
{ id: '56ab0a98-ef5f-474d-a856-50444128109b' },
{ id: '311b9c3f-9f4a-4c84-b7c6-51d583a8abf6' },
{ id: '30361451-a853-46f0-b360-c5adb88cd369' },
{ id: 'b66af759-d3c2-45b0-be1d-efc1b06b3fed' },
{ id: '7699f6e5-edce-485d-b678-0424c7655de2' },
{ id: 'bbb02ef1-c572-4f30-89c9-30c8c71bd98d' },
{ id: '1db4dc43-fba8-4644-9ac8-1482bc5cae3c' }
]