Can MongoDB queries accept additional scopes?

I have two tables listing Decks, which contain Cards. The first table shows Decks that a User is subscribed to, while the second table shows all remaining Decks. I want to set up identical Button columns in each table, which would trigger the same query and opening a modal containing a table of the Cards contained within the Deck whose button was clicked.

I feel that this should be possible using the additionalScope, but I've been struggling for a while now and I can't figure out if I'm the problem, or if this is actually not supported after all. After searching for similar issues here in the Forum, currently my query looks like this:

var value = {"Subscriptions": Subscriptions.data[i]._id, "NonSubscriptions": NonSubscriptions.data[i]._id}[triggeredById]
listCardsInDeck.trigger({
  additionalScope: {"selectedDeckId": value}
})
console.log(value)
console.log(listCardsInDeck.data)

I get the correct Deck ID in console.log(value). However, console.log(listCardsInDeck.data) always returns null.

The listCardsInDeck query is a MongoDB aggregate query. I mention that because I noted some instructions elsewhere saying that you need to define your variables for e.g. PostgreSQL queries, but the MongoDB interface seems not to have a place to do this. So I'm not sure if this is a Retool limitation. Anyway, this is the part of the query where I'm trying to use the additionalScope:

{
    $match: {
      "deckData._id": { "$oid": {{ selectedDeckId }} }
    }
  } 

I'd be very grateful for any insights. I'm rather new to Retool, as well, so I would not be shocked if I were going about this in the wrong way, either.

Hi, welcome to the forums.

Not 100% here but it may simply be a timing issue - the trigger call is async so you might need to await it's return before console.logging the data property or add a success handler, ie

listCardsInDeck.trigger({
  additionalScope: {"selectedDeckId": value},
  onSuccess: function(data) { console.log(data); }
})

Might be that your trigger is firing ok but your console.log fires before it completes

1 Like

First of all, sorry for the delay in replying, @dcartlidge.

Secondly, that seems to have done the trick! Thank you so much.