Sign In Register

How can we help you today?

Start a new topic
Answered

Only way to create MongoDB Index?

Is the only way to create an index to do through cloud code? (a la https://docs.gamesparks.net/howtos/how-to-create-indexes-for-custom-game-collections)


Doesn't appear to be any mechanism in the NOSQL API...


Also I read somewhere (in a scalability doc somewhere) that GameSparks themselves will add indexes based on usage patterns in production - is this true?


Any other info about GameSparks and MongoDB indexes would be appreciated...


Best Answer

Hi Jeff,


Yes, the background option is supported. When using the ensureIndex function, you can pass index options as a second parameter, for example:


Spark.runtimeCollection("playerData").ensureIndex({"playerExp":1},{"background":true});


Vinnie


Hi Jeff,


Apologies for not getting this one addressed sooner. I believe the only way to do this is via Cloud Code at the moment, you can read about itĀ here. I'll double check and confirm this for you. I'll also get more info for you in regards to mongoDB indexes.


Thanks,

Liam

Well I guess you could create a collection with a document containing desired indexes (and the string name of the collection), and in the System event on publish, iterate through all indexes and "ensure" them.


But it does seem like a built in way would be nicer :)


Hi Jeff,

Yes currently the only supported way to create indexes is through Cloud Code, you could index a collection in REST by using a Custom Callback URL, you could pass in what you'd like to index and process it in the Cloud Code script you have for your Custom Callback URL. You can read more about Custom Callback URLsĀ here. We do continually monitor the performance of the database and review where indexes would be beneficial.


Thanks,

Liam

Follow-up question...the example in the above link hooks into the "GamePublished" event so that indexes are created at the creation of the publishing cycle - If I chose to create an index later (via cloud code), can I assume that the "ensureIndex" options includes the MongoDB 'background' option to prevent interference with reads/writes while index is being created?

Answer

Hi Jeff,


Yes, the background option is supported. When using the ensureIndex function, you can pass index options as a second parameter, for example:


Spark.runtimeCollection("playerData").ensureIndex({"playerExp":1},{"background":true});


Vinnie

Login to post a comment