mongodb - How to not list all fields one by one in project when aggregating? -
i using mongo 3.2.14
i have mongo collection looks this:
{ '_id':... 'field1':... 'field2':... 'field3':... etc... }
i want aggregate way:
db.collection.aggregate{ '$match':{}, '$project':{ 'field1':1, 'field2':1, 'field3':1, etc...(all fields) } }
is there way include fields in project without listing each field 1 one ? (i have around 30 fields, , growing...)
i have found info on here:
mongodb $project: retain previous pipeline fields
include existing fields , add new fields document
how not write every field 1 one in project
however, i'm using mongo 3.2.14 , don't need create new field, so, think cannot use $addfields. but, if could, can show me how use it?
basically, if want attributes of documents passed next pipeline can skip $project pipeline. if want attributes expect "_id" value can pass
{ $project: { _id: 0 } }
which return every value except _id.
and if chance have embedded lists or nests want flatten, can use $unwind pipeline
Comments
Post a Comment