简体   繁体   中英

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. I'm using gridfs-stream to access the collection. 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'. 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) {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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