Is It Possible Rename Fields In The Outputs Of A Mongo Query In Pymongo?
I have some documents in Mongo: {'name' : 'John', 'age' : 26} {'name' : 'Paul', 'age' : 34} {'name' : 'George', 'age' : 36}  and another function that expects documents of the form
Solution 1:
I'd use the aggregate method with $project operator.
From mongodb web docs.
You may also use $project to rename fields. Consider the following example:
db.article.aggregate(
 { $project : {
     title : 1 ,
     page_views : "$pageViews" ,
     bar : "$other.foo"
 }} );`
e.g.
db.mycol.aggregate({ $project : { name:1, value:"$age" }});
see http://docs.mongodb.org/manual/reference/aggregation/#_S_project
Post a Comment for "Is It Possible Rename Fields In The Outputs Of A Mongo Query In Pymongo?"