Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to construct complex queries against noSQL DB

Tags:

nosql

I have been researching noSQL DB and have not been able to satisfactorily answer this for myself: Is it possible to construct complex queries against noSQL DB?

The type of query I'm wondering about would be something like this:

select * from DB where
vara > x AND
varb = 2 AND
varc < x AND
vard in (x,y,z) AND
vare like '%texthere%' AND
varf = 2 AND
varg = 3 and
etc...

NOTE: I'm aware that I can't use SQL, as above, what I'm asking is how would I query using the psuedo logic above, in other words a whole bunch of different conditions. So far the best answer I have found is that you have an RDBMS to query and then grab data based on key from cloud. That doesn't necessarily seem more efficient to me.

So as a follow up. If just trying to solve a 'search 4 million rows' problem as opposed to a 'we have billions of rows of data' problem, should I even bother looking at a noSQL DB?

like image 389
Tom DeMille Avatar asked Feb 28 '10 12:02

Tom DeMille


People also ask

Can NoSQL handle complex queries?

It can also provide faster recovery and storage and handle complex queries. If you're working to extend the RDBMS standard structure or build a flexible schema, NoSQL databases are a better choice than SQL. They can also be used for storing and accessing data from various sources, such as distributed databases.

Can you query a NoSQL database?

NoSQL was never about getting rid of SQL; it was about using non-relational data models where they were better suited. Query might not have been the priority for all of them but now we can expect rich query from non-relational databases as well as everything else they have to offer.

Which database is best for complex queries?

SQL supports complex queries because it is a very expressive, mature language.

Is MongoDB good for complex queries?

MongoDB is designed to make data easy to access, and rarely to require joins or transactions, but when you need to do complex querying, it's more than up to the task. The MongoDB Query API allows you to query deep into documents, and even perform complex analytics pipelines with just a few lines of declarative code.


3 Answers

In mongodb, you would just do something like db.mytbl.find({"vara": { $gt: 10}, "varb": 2, "varc": {$lt: 100 }})

See here, and here for examples

like image 146
nos Avatar answered Oct 20 '22 20:10

nos


It depends on the data store you are using.

I frequently use AppEngine and their data store only allows inequality on one column (and that column must be the first element in the sort order. So you would not be able to run the query you posted, but you could do a similar one:

select * from DB where
vara > x AND
varb = 2 AND
varc in (t,u,v,w)
vard in (x,y,z) AND
varf = 2 AND
varg = 3

Also, you can do things like have a column that contains a list of strings and select rows that have a value in the list.

So, the official answer is "maybe, sorta, sometimes, but not really, except when yes"

like image 29
Jackson Miller Avatar answered Oct 20 '22 22:10

Jackson Miller


I'not a NoSQL expert, but as the name says, they don't rely necessary on SQL. You can probably do whatever you want, but will need to code map/reduce function or other non-SQL way to query the data.

Maybe this blog provide useful information to you: Query processing for NoSQL database

like image 41
ewernli Avatar answered Oct 20 '22 21:10

ewernli