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.
So, I figured that out and here's the code to do it:
get '/:year', (page, model, params) ->
query = model.query 'years',
where:
year: (parseInt params.year, 10)
limit: 1
model.subscribe query, (err, year) ->
if err
console.log err
page.render
y: year.get(),
year: params.year
The only problem is that the documents don't have a derby id, so it sets the MongoDB objectid (_id) to the derby id. Here's an example of the JSON that the model.get()
returns: https://gist.github.com/0a5426d2b28a940e8803
I have no way of knowing what the objectid is before the query. I would love if the most recently returned id (currID
) was in the object's top level so I could just query that and set a model reference. I built a hack to get around it for now, but it's not as smooth as I wish it would be. The code is below:
getId = (obj, year) ->
for x of obj
return obj[x].id if obj[x].year is year
-1
Also, is there any way to update templates without destroying some templates already on the screen? Instead of doing a full page.render
just doing a template.render
?
Thanks
Racer queries were just updated in 0.3.11, and are described in this readme file: https://github.com/codeparty/racer/blob/master/lib/descriptor/query/README.md