Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Update one Database-Collection based und values in another collection

Issue

Hi, I am new to Appsmith and JS. I have created an app that reads data from MongoDB and updates it. Now I need to update the "occupied" flags of the "workplaces" collection based on the selection made in the "students" collection. I have a query that collects the unoccupied workplaces, but I am struggling to update the flags based on the selected workplaces. I also have issues with a dropdown-select input changing to a number or text input randomly. I am also facing performance issues with accessing data fields in MongoDB objects. How can I directly access one field in a MongoDB object using its ObjectId? Any help would be greatly appreciated.

Resolution

In summary, the user Marius was having issues with updating the occupied-flags of the Workplaces-collection in their Appsmith and JS application based on the selection in the Students-Collection. They were able to query for the selection-dropown that collects only unoccupied-flagged workplaces but were lost on how to update the flags by means of the used workplaces in the Students table. A community member suggested using ‘All Matching Documents’ as Limit to update multiple records by using the $in operator to update a list of IDs.

Marius later faced issues with the Select Input which kept changing, but the community member was unable to reproduce the issue. They asked Marius to share the app to debug the scenario. Marius also faced issues with a function that returns a boolean Value depending on whether a field in a certain ID is empty or not. They further faced performance issues in accessing single data fields in a MongoDB object when for loops were needed to check where the ID matches. A community member suggested using an aggregate query to return the required field only.