折腾:
期间,由于用:
> db.fs.chunks.find({files_id: ObjectId("5abb397ca4bc71fc7d71c7bd")})
会返回chunk的data,导致数据太多,刷屏太多,看不清个数了:
所以需要想办法去:
如果查询一个file下面有多少个chunks,只返回个数,或者是个数+id,不带chunks.data,以方便查看。
mongodb list count of gridfs file chunks
mongodb gridfs file chunks count
mongodb command show count
去试试length
> db.fs.chunks.find({files_id: ObjectId("5abb397ca4bc71fc7d71c7bd")}).length function () { return this.toArray().length; } > db.fs.chunks.find({files_id: ObjectId("5abb397ca4bc71fc7d71c7bd")}).length() 32
用
提到的count也是可以的:
> db.fs.chunks.find({files_id: ObjectId("5abb397ca4bc71fc7d71c7bd")}).count function (applySkipLimit) { var cmd = this._convertToCountCmd(applySkipLimit); var res = this._db.runReadCommand(cmd); if (res && res.n != null) return res.n; throw _getErrorWithCode(res, "count failed: " + tojson(res)); } > db.fs.chunks.find({files_id: ObjectId("5abb397ca4bc71fc7d71c7bd")}).count() 32
【总结】
此处可以通过:
db.fs.chunks.find({files_id: ObjectId("5abb397ca4bc71fc7d71c7bd")}).length()
或:
db.fs.chunks.find({files_id: ObjectId("5abb397ca4bc71fc7d71c7bd")}).count()
都可以查看到:
find出来的结果的个数。
转载请注明:在路上 » 【已解决】MongoDB的GridFS中只返回file的chunks的个数而不返回chunks.data