Am 10/21/2012 10:21 AM, schrieb mist:
Ugh, all this makes me think part of bson/json will need kind of revamp
one day to provide way to do such typical tasks more efficiently.
On Sun, 21 Oct 2012 08:04:10 GMT, Sönke Ludwig wrote:
Hm.. I thought
~=was defined for
Json, but for some reason I left
it out in the initial commit of json.d. A workaround is of course to
use an actual array:
Json arr; foreach( doc; coll.find() ) arr ~= doc.toJson(); auto json = Json(arr);
I'll look into why
~=is not defined.
Well, I wouldn't call it revamp ;) but certainly there are some corners
that can be improved. In the case of just returning a list of DB
documents I would imagine at least this should be possible:
auto json = Bson(coll.find().array()).toJson();
but that would more be
MongoCursor, which needs to get a range
interface (or does array() already work on iterable things?)
The thing with JSON/BSON is that I would like to avoid a cyclic
dependency between the two; so Json may never directly know about Bson,
which restricts a bit of what is possible.