Is it possible to use a SQL style 'union' and 'pseudo column' in a MongoDB query?
-
Can the following sql query be done as a mongo query? (this would solve a big problem for me) select * from ( select attribute1, '100' from collection where attribute2 = 1 union select attribute1, '200' from collection where attribute2 = 2 ) where rownum between 1 and 20 order by attribute1
-
Answer:
Something like this? db.collection.find({$or: [ {attribute2: 1}, {attribute2: 2}]}).sort({attribute1:1}).limit(20)
Harry Heymann at Quora Visit the source
Other answers
So MongoDB doesn't have the "pseudo column" in the query language. However, I'm not clear that your query actually requires either the "pseudo column" or the "union". The "pseudo column" is just a function of attribute2 and the union is basically an "OR" clause. Did you mean "order by pseudo column"?
Gaëtan Voyer-Perrault
Take a look at the Aggregation framework in 2.1.0 and above. http://www.mongodb.org/display/DOCS/Aggregation+Framework This would allow for the projection of the '100' and '200' values during the processing.
Alvin Richards
Related Q & A:
- Is it possible to use a phone camera as a webcam?Best solution by Yahoo! Answers
- Is it possible to use a webcam on Yahoo Messenger for Mac?Best solution by Yahoo! Answers
- Is it possible to use a game controller as a mouse?Best solution by Yahoo! Answers
- Can you use a wire dog crate (like a Midwest) on a Via Rail train?Best solution by Yahoo! Answers
- Is it possible to do a component to s-video to rca for a video signal?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.