-
-
Save tomspeak/93e02db60f90e69d645738048ec2620b to your computer and use it in GitHub Desktop.
This file contains 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
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 | |
} | |
] | |
} | |
} | |
} | |
*/ |
This file contains 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
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