Last active
April 16, 2019 12:46
-
-
Save kobalski/7cabb930f078a193e9a0cf3e02714a9a to your computer and use it in GitHub Desktop.
thundra-mongose-example
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 thundra = require("@thundra/core")(); | |
const mongoose = require('mongoose'); | |
let conn = null; | |
const uri = 'your mongo connection here'; | |
exports.handler = thundra(async function(event) { | |
if (conn == null) { | |
conn = await mongoose.connect(uri, {useNewUrlParser: true}); | |
conn.model('Test', new mongoose.Schema({ name: String })); | |
} | |
return Handler(); | |
}); | |
async function Handler() { | |
const M = conn.model('Test'); | |
const m = new M; | |
m.name = 'Thundra'; | |
m.save(); | |
return M.findOne(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment