I have some data I am trying to retrieve from mongodb into R using rmongodb package. At some point in time, the ordering of the fields in the stored documents changed.
I am trying to force my projection query to keep the order of the fields projected fixed by explicitly specifying approach attempted in: SO question as follows:
data <- mongo.find.all(mongo_conn, table,
fields = list('id1' = 1, 'id2' = 2,
'time' = 3, 'latitude' = 4,
'longitude' = 5, '_id' = 0))
I can't seem to find a good answer to this. It returns the fields in the order they are in the DB, which changed, as a list of course.
That means, it wreaks obvious havoc in what kind of loopy code I have to write to organize the returned results into a data frame like structure.
Any idea how I can get the fields in specified order and not what is in DB?
In the answer you link to it says
Also see the related mongodb ticket
However, to get your results in a
data.frame-like structure, usemongolite, it's much easier to work withConsider this example using the mtcars data
mongolite::findwill automatically simplify the query results into a data.frame structureOr, using the aggregation framework
And now for a bit of shameless self-promotion. I've been working on an extension to mongolite that returns a data.table object. The idea here is to increase the speed of returned objects, but only if the returned result set can be coerced using
rbindlist.The package is
mongolitedt, and still in development.