我想增加views
每次访问我的文档时都会加 1。到目前为止,我的代码是:
Document
.find({})
.sort('date', -1)
.limit(limit)
.exec();
哪里有$inc
适合这里吗?
从未使用过猫鼬,但快速查看文档here http://mongoosejs.com/docs/finding-documents.html看来这对你有用:
# create query conditions and update variables
var conditions = { },
update = { $inc: { views: 1 }};
# update documents matching condition
Model.update(conditions, update).limit(limit).sort('date', -1).exec();
干杯,祝你好运!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)