I love the Maygogol dead man, but I'm at a dead end. I would like to get the results of a simple .find () to return in the same JSON format that matches the Mongo command line output:
$ db.mycollection.find(); # outputs.. # { ...some data... , "_id" : ObjectId("4f0b371c0000008b6d000008") }
However, with deedbeef, the .find () method does not return a result or does not provide a callback. So I used .toArray (); which seems right to me.
Mongolian = require("mongolian"), server = new Mongolian, db = server.db("mydatabase"), mycollection = db.collection("mycollection"), mycollection.find().toArray(function(err, data){ res.write(JSON.stringify(data)); });
Dumping the _id binary (I assume this is a buffer) results in the @ # $ metric! tons of data. What is the correct way to return JSON from mycollection.find ()?
~~~~~~~
I was able to remove _id from the results using the following command:
mycollection.find({}, { id:0 }).toArray(function(err, data){ res.write(JSON.stringify(data)); });
However, the big problem associated with converting _id from JSON to BSON remains.
source share