2013-10-22 47 views

回答

1

我不知道有任何mongodb插件。最简单的出发点可能是采取tubmlr plugin并使其适应读取形式mongodb而不是从tumblr rss/atom feed中读取。

该插件的代码不是非常复杂。首先,您需要将fetchTumblrData函数替换为从MongoDB获取数据的函数,然后您想要修改the code in populateCollections以将该数据转换为虚拟文档。

0

我一直在研究一些代码,现在可以从Mongodb中读取并返回一个可以呈现为文档的对象。我还试图编写一些代码来为数据库的基本编辑提供后端,但更新后的再生尚未运行(尽管可能在您阅读本文时!)。

下面是关键部分(与BALupton协助解决回调复杂问题)。

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 
    @ 

https://github.com/simonh1000/docpad-plugin-mongo