I have been working on some code that can now read from Mongodb and return an object that can be rendered into docs. I've also tried to write some code to provide the backend for basic editing of the database but the regeneration after update is not yet working (although it may be by the time you read this!).
The key section (with credit to BALupton for helping with the callback complexity) is below.
extendTemplateData: (opts,next) ->
config = @getConfig()
mongoose.connect(config.uristring)
db = mongoose.connection
db.on 'error', (err) ->
docpad.error(err) # you may want to change this to `return next(err)`
db.once 'open', ->
queries = config.queries
queryCount = 0
totalQueries = Object.keys(queries).length
for index, query of queries
((indexClosure) ->
Dbdata.find query.predicate, (err, data) ->
opts.templateData[indexClosure] = data
if (++queryCount == totalQueries)
mongoose.connection.close()
return next(err) if err
return next(null, data)
)(index)
# Chain
@
See https://github.com/simonh1000/docpad-plugin-mongo