Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
MongoDB and Gideros — Gideros Forum

MongoDB and Gideros

totebototebo Member
edited October 2015 in General questions
Has anyone used MongoDB with Gideros? If so, which Lua library did you use?
My Gideros games: www.totebo.com

Comments

  • hgy29hgy29 Maintainer
    You mean accessing a MongoDB instance remotely through sockets from gideros ? This never came to my mind although I use MongoDB regularly...
  • Precisely! Is it possible?!
    My Gideros games: www.totebo.com
  • I actually saw couple of solutions, but have not tried any of them

    This seems promising:
    https://github.com/cloudwu/lua-mongo
  • jdbcjdbc Member
    edited October 2015
    The best way is to use UrlLoader Gideros class with a Rest API + MongoDB. It is quite easy to build it in Openshift.

    https://github.com/openshift-quickstart/openshift-mongo-node-express-example
    https://blog.openshift.com/getting-started-with-mongodb-on-nodejs-on-openshift/

    Anyway if you only need store some data, use Parse: https://www.parse.com/ I have provided the Lua code to create and update data in Parse in other threads in the forum.
  • I'm looking to store and share level editor data. Could Parse do that, and is it suitable?
    My Gideros games: www.totebo.com
  • I'm looking to store and share level editor data. Could Parse do that, and is it suitable?
    If your level editor data are JSON then it should work with Parse REST API and Gideros UrlLoader class:
    https://parse.com/docs/rest/guide#quick-reference

    For example create a JSON object with the following code:
     
    require "json"
     
    local headers = {
    					["X-Parse-Application-Id"] = "XXXXXXXXXXXXXX",
    					["X-Parse-REST-API-Key"] = "XXXXXXXXXXXXXX",
    					["Content-Type"]  = "application/json"
    					}
     
    -- Create a new object on Parse (<a href="https://www.parse.com/docs/rest#objects-classes" rel="nofollow">https://www.parse.com/docs/rest#objects-classes</a>)
    function ParseAPI.createObject(className, object)
     
    	print("ParseAPI.createObject", className)
     
    	if (className and object) then
    		local url = "<a href="https://api.parse.com/1/classes/"..className" rel="nofollow">https://api.parse.com/1/classes/"..className</a>
    		local method = UrlLoader.POST
     
    		-- Session token added to headers
    		--addSessionToken()
     
    		local body = json.encode(object)
    		--print("body", body)
     
    		local loader = UrlLoader.new(url, method, headers, body)
     
    		local function onComplete(event)
    			print("createObject() onComplete", event.data)
     
    			local response = json.decode(event.data)
    			local objectId = response.objectId
    			dataSaver.saveValue(className, objectId)
     
    			if (level_manager) then
    				level_manager:syncronize(response)
    			end
    		end
     
    		local function onError()
    			print("onError")
    		end
     
    		local function onProgress(event)
    			--print("onProgress: ")
    		end
     
    		loader:addEventListener(Event.COMPLETE, onComplete)
    		loader:addEventListener(Event.ERROR, onError)
    		--loader:addEventListener(Event.PROGRESS, onProgress)
    	else
    		print("Error: class name or object is nil")
    	end
    end
  • @jdbc thanks! Looks great, thanks for the heads up and the code.
    My Gideros games: www.totebo.com
Sign In or Register to comment.