Skip to content

Instantly share code, notes, and snippets.

@tomspeak

tomspeak/find.js Secret

Created January 24, 2017 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomspeak/93e02db60f90e69d645738048ec2620b to your computer and use it in GitHub Desktop.
Save tomspeak/93e02db60f90e69d645738048ec2620b to your computer and use it in GitHub Desktop.
const choiceId = '588776235f5cab3f9af45e81'
pollModel.findOneAndUpdate(
{ 'choices._id': choiceId },
{ $inc: { 'choices.$.votes': 1 } },
{ new: true }
)
/**
{
"data": {
"message": "OK",
"poll": {
"_id": "588776235f5cab3f9af45e7f",
"title": "TEST",
"url": "wgrcx",
"choices": [
{
"title": "Test API Choice 1",
"_id": "588776235f5cab3f9af45e81",
"votes": 15
},
{
"title": "Test API Choice 2",
"_id": "588776235f5cab3f9af45e80",
"votes": 0
}
]
}
}
}
*/
const PollSchema = new Schema({
title: String,
choices: [
{
title: String,
votes: { type: Number, default: 0 }
}
],
date: { type: Date, default: Date.now },
url: String,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment