Created
March 15, 2023 20:22
-
-
Save afbelardi/afaa6503e95153b6494b2409c9ffacf7 to your computer and use it in GitHub Desktop.
A function in a NestJS backend to increment page views for a user's profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async addPageViews(id) { | |
const newDate = new Date(Date.now()) | |
return await this.AnalyticsModel.findByIdAndUpdate(id, { $push: {"pageViews.datesViewed": newDate}, $inc: {"pageViews.timesViewed": 1}} ,{ new: true }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment