1

I'm running into two issues with Derby and Mongo. I come from a MySQL and Redis background so maybe I'm just doing something wrong?

1) It seems I can't search for an Id whose type is ObjectId.

model.query("users").byKey(params.userId);

Will only match records whose _id is a string.. Which I guess would be okay, except when the data is "updated" Racer will create a new record with an ObjectId _id! So basically I can't ever retrieve a document by id that I've inserted with Racer!

2) Every time I do a query I get back an object of objects such as:

{ '$spec': true, 
    '4fcd4c8e6c8c89d97ed90f4a': { "username": ... },
    '4fcd4c8e6c8c89d97ed90f4b': { "username": ... },

Which means I have to convert it into a list of objects. I wrote a function that creates a list of the _id's, then assigns it to a model variable for use with refList. It feels like such a hack, this can't be the right way to do it.

Alexis
  • 707
  • 8
  • 33
Stephen Corgiat
  • 105
  • 1
  • 7
  • Did you ask in the derbyjs google group also? https://groups.google.com/forum/?fromgroups#!forum/derbyjs – studgeek Jun 12 '12 at 15:08

2 Answers2

2

Queries were just substantially updated in version 0.3.11. Models now have built-in model.filter() and model.sort() methods which will replace the need to manually build a list of keys and emit much more efficient array update events to Derby.

Please see the Queries README.

Pavel Zubkou
  • 825
  • 9
  • 13
Nate Smith
  • 459
  • 4
  • 6
0

I'm not a derbyjs user, however here are some suggestions regarding your problems:

1) Regarding "Id is ObjectId"?

It seems that id have to be an object, see DerbyDoc/Persistance:

Racer paths are translated into database collections and documents using a natural mapping: collection.documentId.document

...

// The first and second segments in root paths must be objects

How are you saving your data? As a general advice, a full reproducible code would improve the help you can get.

2) "I need to convert the query result to list"?

From my experience with other engines, it indeed seems you're not using the right approach. All will depend on what you want to do with the result, but one very common approach is to work with object list and finally get attributes in a template loop. In your case it will mean pass directly the query result to the page.render call. See DerbyDoc/sections

Hope this helps

Alexis

Alexis
  • 707
  • 8
  • 33
  • On #1, I think you're referencing something different, that is for a model path that has already been established. The issue is that when I pass an "id" to model.query it appears to do the equivalent of db.users.find({"_id": "12345"}) versus db.users.find({"_id": new ObjectId("12345")}). – Stephen Corgiat Jun 06 '12 at 05:45
  • As for #2, Meteor (a similar framework) accepts an object of objects much like what I would expect Derby's behavior to be. With KnockoutJS, for example, it is necessary to convert the objects to a list of objects before being able to loop through them in a template, but I'm hoping someone with experience with Derby can provide an example of the correct way (if there is one) of doing it. – Stephen Corgiat Jun 06 '12 at 05:50
  • Ok, as I said I'm not really a derbyjs user, so I hope you'll get your answers ( even though it seems there aren't so many followers of derbyjs here ) – Alexis Jun 06 '12 at 06:44