我试图通过向我的3个集合传递3个不同的链接来检索3个食物清单,例如

redFoods = collection1.find(redLink)
blueFoods = collection2.find(blueLink)
greenFoods = collection3.find(greenLink)

Where

redFoods = [red1, red2, red3, ... , redN]
blueFoods = [blue1, blue2, blue3, ... , blueN]
greenFoods = [green1, green2, green3, ... , greenN]

然后,我想把redFoods、blueFoods和greenFoods合并为一个列表,将食物交替使用。

[red1, blue1, green1, red2, blue2, green2, red3, blue3, ... , redN, blueN, greenN]

我怎样才能通过MongoDB在一个查询步骤中做到这一点?

到目前为止,我已经试过了,但这似乎并不奏效。

redLink = "meat"
blueLink = "fruit"
greenLink = "veggies"
shoesList = redFoods.aggregate([
                '$match': {
                    'Link': {
                        redLink
                '$unionWith': {
                    'coll': 'blueFoods',
                    'pipeline': [
                            '$match': {
                                'Link': {
                                    blueLink
                '$unionWith': {
                    'coll': 'greenFoods',
                    'pipeline': [
                            '$match': {
                                'Link': {
                                    greenLink
    
python
python-3.x
database
mongodb
syntax
sytactive
sytactive
发布于 2021-02-24
1 个回答
Raymond Reddington
Raymond Reddington
发布于 2021-02-24
已采纳
0 人赞同
'$match': { $or: [ { 'Link': redLink },