How to read all objects from postgres storage in Nakama Go lang

I’m building a game where each user submits some data from the client to the server. I’m saving this data in Postgres. Once all the players are “ready” in my lobby, I would like to go and pick a random piece of data that was previously submitted by one of my players. However, I’m having trouble to grab all the data from a given collection from the server. I can only read the data to the latest user to call the MatchLoop. As part of the object that I am storing I have a property called “shown”, I would love some help on how to filter for not shown image from the entire collection.

  1. Versions: Nakama 3.15.0, Windows| Docker, GitHub - heroiclabs/nakama-common: The runtime framework for Nakama server. v1.26.0
  2. Server Framework Runtime language (If relevant) Go
// Tried not specifying key of userid to read all records from the collection but did not get any data back
objectIds := []*runtime.StorageRead{
	&runtime.StorageRead{
		Collection: "images",
	},
}

// I am currently just reading whatever the last image I get from the latest user to hit MatchLoop
objectIds := []*runtime.StorageRead{
	&runtime.StorageRead{
		Collection: "images",
		Key:    matchID,
		UserID: userID,
	},
}

objects, err := nk.StorageRead(ctx, objectIds)

// I'm sending a base 64 of the image from the client directly to the database this is my JS code
      // Upload base64 image to database directly from client
      await ctx.client.writeStorageObjects(ctx.session, [
        {
          "collection": "images",
          "key": matchId,
          "value": data,
        }
      ]).then(async _ =>
        //....
      );

:tv: Media:

Hi @rpparede, there’s a function for listing all records in a collection: StorageList

@ftkg thanks, I have somehow skipped this function. My question is how can I filter the results I get from StorageList? I would love to only get results that have “shown”: false. I was thinking this would be a good case to write my own postgres query but the docs recommended to check with you first. I can write some code on my server to go through all the objects and find the ones with shown:false but that seems expensive that I have to read all objects everytime.

Hello @rpparede please have a look at Heroic Labs Documentation | Storage Search I think this will cover your needs.