Question

I'm evaluating RethinkDB as a Mongo replacement due to lack of stable Mongo drivers on Node. I've read the docs at http://www.rethinkdb.com/api/javascript/get_all/ and have a very simple question: how do I get a document by key value pair?

The examples for get() only talk about the index. I'm not interested in the index, but rather other fields. Eg, I'd like to be able to do:

.get({someField:SomeValue}) 

... in much the same way I'm used to with collection.find() on Mongo. But that doesn't seem possible. What am I doing wrong? Is fetching a document this way not considered a get?

Should I be using .filter() for this instead?

Was it helpful?

Solution 2

You also can use getAll(), but first you create an index for that field:

r.db('test').table('testtable').indexCreate('someField')

You can then use getAll() to get a stream of results:

r.db('test').table('testtable').getAll('SomeValue', {index :'someField'});

This is faster than filter().

OTHER TIPS

It looks like Rethink's .filter is the appropriate equivalent to Mongo's find().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top