Skip to content

Instantly share code, notes, and snippets.

@afbelardi
Created March 15, 2023 20:22
Show Gist options
  • Save afbelardi/afaa6503e95153b6494b2409c9ffacf7 to your computer and use it in GitHub Desktop.
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
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