存储架构

Union query in mongodb without using map/reduce

微信扫一扫,分享到朋友圈

Union query in mongodb without using map/reduce
0

Yes, I checked other union questions here, however this seems to be different.

Here is the SQL query I’d like to convert for mongo

SELECT column1 from table1

UNION

SELECT column1 from table2

In my mongo database I could have up to 12 collections, one for each month.

data.2013.01
data.2013.02
.
.
data.2013.12

When plotting I’d like to show multiple months on graph at a time. That brings us to the question, how to create UNION in mongo.

Problem courtesy of: functionoid

Solution

I think the ultimate conclusion you will come to is that your schema is incorrect. Put all your objects of the same purpose and shape into a single collection. That’s how to work in harmony with mongodb. Making collections by month is a mistake that will cause you endless needless battles with mongo. Once you have everything in one collection as intended, the aggregation can handle grouping by month for you as per the aggregation example of usernames ordered by join month
.

Solution courtesy of: Peter Lyons

阅读原文...

微信扫一扫,分享到朋友圈

Union query in mongodb without using map/reduce
0
Node.js Recipes

Building Azure SQL Db with Terraform with Visual Studio Code

上一篇

实现一个简单的基于Token的身份认证

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

Union query in mongodb without using map/reduce

长按储存图像,分享给朋友