简体   繁体   English

按元数据排序Mongodb的Nodejs驱动程序

[英]Sorting by metadata Mongodb's Nodejs driver

I'm using Gridfs to store files and allow the possibility of storing the same file but incrementing a version variable in the file's metadata. 我正在使用Gridfs来存储文件,并允许存储相同文件,但增加文件元数据中的版本变量的可能性。 I'm using gridfs-stream to access the collection. 我正在使用gridfs-stream访问该集合。 So I'm trying to get the latest version out of the collection and I know I can use: 因此,我正在尝试从集合中获取最新版本,我知道我可以使用:

{sort: [['uploadDate', 'desc']]}

but I'd like to sort by the metadata version field that is named '__v'. 但我想按名为“ __v”的元数据版本字段进行排序。 I'm guessing the format to do that is this: 我想这样做的格式是这样的:

gfs.collection().findOne({'metadata.fd': fd}, {sort: [['metadata.__v', 'desc']]}, function(err, file) {}
gfs.collection().findOne({'metadata.fd': fd}, {}, {sort: {'metadata.__v': -1}}, function(err, file) {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM