mongodb - How to exclude _id without including other fields using the aggregation framework -
i result of aggregation pipeline without _id filed. know possible if provide explicitly other fields output of projection. but, ¿how can mimic $projec in find call?
this want (no field explicitly included):
db.col.find({},{_id:0}) but in aggregation framework seems impossible:
db.col.aggregate([{'$project': {_id:0}}]) error: printing stack trace @ printstacktrace (src/mongo/shell/utils.js:37:15) @ dbcollection.aggregate (src/mongo/shell/collection.js:927:9) @ (shell):1:11 2013-10-07t16:36:09.273+0200 aggregate failed: { "errmsg" : "exception: $projection requires @ least 1 output field", "code" : 16403, "ok" : 0 } @ src/mongo/shell/collection.js:928 any idea workaround issue ?
when using aggregation, must explicitly include/exclude fields. so, you'd need list fields want. it's not equivalent find. so, might:
db.sample.aggregate( { $project : { _id : 0, title : 1 }} ); using aggregation framework comes limits should aware of. it's designed aggregation (grouping, summing, etc.), having many fields in projection isn't typical (and cause results exceed maximum allowed, 16mb).
Comments
Post a Comment