我使用以下js代码为我的Web应用程序运行服务器:
mongoose.Promise = Promise
mongoose.connect('mongodb://127.0.0.1:27017/appdb')
.then(() => console.log('Mongoose up'))
const User = require('./models/users')
app.use(bodyParser.json())
app.post('/api/login', async (req, res) => {
const {email, password} = req.body
const resp = await User.findOne({email, password})
if(!resp) {
res.json({
success: false,
message: "Incorrect details"
})
} else {
res.json({
success: true
})
}
})
和UserSchema(users.js):
const UserSchema = new mongoose.Schema({
email: String,
password: String,
quote: {type: String, default: "You have no quote"}
})
const User = mongoose.model('users', UserSchema)
module.exports = User
我需要为此做准备才能在Firebase实时数据库上工作。但是我对如何使用该数据库知之甚少。
我正在尝试:
var usersRef = database.ref('users');
usersRef.on('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var resp = childSnapshot.val();
});
});
但是我收到内部服务器错误。
我在做什么错了?