简体   繁体   中英

Import “normal” MongoDB collections into DerbyJS 0.6

Same situation like this question, but with current DerbyJS (version 0.6):
Using imported docs from MongoDB in DerbyJS

I have a MongoDB collection with data that was not saved through my Derby app. I want to query against that and pull it into my Derby app.

Is this still possible?

The accepted answer there links to a dead link. The newest working link would be this: https://github.com/derbyjs/racer/blob/0.3/lib/descriptor/query/README.md

Which refers to the 0.3 branch for Racer (current master version is 0.6).


What I tried

  • Searching the internets
  • The naïve way:

     var query = model.query('projects-legacy', { public: true }); model.fetch(query, function() { query.ref('_page.projects'); }) 

    (doesn't work)

A utility was written for this purpose: https://github.com/share/igor

You may need to modify it to only run against a single collection instead of the whole database, but it essentially goes through every document in the database and modifies it with the necessary livedb metadata and creates a default operation for it as well.

In livedb every collection has a corresponding operations collection, for example profiles will have a profiles_ops collection which holds all the operations for the profiles.

You will have to convert the collection to use it with Racer/livedb because of the metadata on the document itself.

An alternative if you dont want to convert is to use traditional AJAX/REST to get the data from your mongo database and then just put it in your local model. This will not be real-time or synced to the server but it will allow you to drive your templates from data that you dont want to convert for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM