Select specific fields


Due to the size of some objects and the limitation in memory on Cloudcode, I was hoping to find a way to select only IDs or specific fields along with it. Something along the lines of:

const objects = await DB.object.where('somefield = ?', 'value').fields('id', 'name').toArray();

It would be greatly appreciated if there is a workaround for this.

Hey @eugene_ca

At time of writing this is not possible, but we have received that feature request from other developers as well and will hopefully be in a position to add support for something along those lines in a future release.

I guess the current workaround is to create that sub structure / collection yourself, an array of just IDs or an array of JSON objects with ID and name as fields. You will then just have to build it up in smaller tranches to avoid the memory build-up, so instead of fetching all and then building up this new collection, you fetch in batches of 100 or something and then build the new collection up bit by bit. In doing it this way to minimize the memory footprint that the large DB objects could have by working with a smaller batch of them at any point in time whilst still eventually building up the entire new collection

Sorry if that workaround was obvious.

Another potential workaround is to use our OPSQL service and query the data from SQL instead, where you could select only the fields you are interested in. :face_with_diagonal_mouth:

Hi @tielman ,

Thank you for the workaround, I’ll go that route for now and be on the lookout for a future update.