我正在使用PouchDB和Express从数据库中获取文档:
server.js:
var express = require('express')
var PouchDB = require('pouchdb')
var app = express()
var db = new PouchDB('vuedb')
// handle PouchDB stuff
app.get('/docs', function(req, res) {
function map (doc, emit) {
if (doc.type === 'project') {
emit(doc.createdAt)
}
}
db.query(map, {include_docs: true}).then(function (projects) {
// _.map(projects.rows, (project) => (project.doc))
console.log('PROJECTS', projects)
})
// res.send()
})
client.js:
submit () {
this.$http.get('http://localhost:8080/docs').then(response => {
// console.log(response) does log the response, so this submit() action is working
}).catch(err => console.log(err))
}
我想确认是否正在获取projects
。但console.log('PROJECTS', projects)
并未在终端中记录任何内容。为什么是这样?是否有一种特殊的方式在Express中记录东西?
答案 0 :(得分:1)
不,不是那样的。问题是,它可能在之前达到错误状态。尝试捕捉该错误
db.query(map, {include_docs: true}).then(function (projects) {
// _.map(projects.rows, (project) => (project.doc))
console.log('PROJECTS', projects)
}).catch(function (e) {
console.log(e);
})