Hubert Kario
Hubert Kario

Reputation: 22810

NoSQL database with range queries

I'm looking for a NoSQL database that allows queries that return records that fall in the specified range.

I'm not very good with the NoSQL nomenclature (as I'm still only researching whatever they will be viable) so I'll explain it how I would do it in SQL.

What I'll need to do, is search for records (let's say forum posts), that are above a specific score. More or less something like this: SELECT * FROM posts WHERE score > 2.

The question being, when I'm using PHP, is it possible to do with any NoSQL database (key-value or wide column ones)? If it's impossible with any, which NoSQL databases support such queries?

Upvotes: 4

Views: 5961

Answers (2)

Lvca
Lvca

Reputation: 9060

OrientDB supports SQL with extensions for the schema-less paradigm.

You can execute this query:

SELECT * FROM posts WHERE score > 2

But the underlying index is not used with operators different by = (equals). So it could be not so fast with millions of records because it need to scan the entire cluster to satisfy the condition (something similar to a table in relational world).

Upvotes: 0

Daniel Vassallo
Daniel Vassallo

Reputation: 344291

You may want to check out MongoDB. It's popular1, and supports range queries:

Unlike many other non-relational database solutions, any field can be queried at any time. MongoDB supports range queries, regular expression searches, and other special types of queries in addition to exactly matching fields. Queries can also include user-defined JavaScript functions (if the function returns true, the document matches).

From: Wikipedia - MongoDB Features

Here's how your SELECT * FROM posts WHERE score > 2 query would look like in Mongo:

db.posts.find( { score : {$gt: 2} } );

Further reading:


1 See: MongoDB : Production Deployments

Upvotes: 2

Related Questions