Thanks for that clarification. As I am still a bit of a programming newbie, I am still a bit confused on how to write this new method. After checking the Mongo docs I am even more confused as to how I can slot it into Corona/coronium. Any further help would be GREATLYY appreciated! Thanks!
And yes all I want to do is append the array, and by the sounds of it I want to use the push method. It shouldn’t be this complicated?
You will probably want to follow the cloud code docs to write that function. http://docs.coronium.io/en/latest/devel/CloudCode/
That is the best way at the moment to add/override functionality and still preserve updatability.
I’m speaking for Chris, hope he doesn’t mind. Coronium was built to handle a specific set of use cases and has well documented API methods for those cases. In your circumstance you are wanting to extend that functionality, so yes it will take some lifting on your part to implement that. That is the cost of using Open Source or free software. If you are uncomfortable or unable to pay this price, you may want to look into something that fits closer to your requirements or hire a developer that can implement it for you.
Thanks, Steven. I really appreciate your help with this. Any idea on what the method should be?
David,
Actually just thought about it some more. You could use Data Objects and setup your schema as such:
{
userID: XXXXXXXX,
order: {
…
}
}
Then you could just query all orders from that table as each individual order would have its own entry. It does require two round trips, one to get the user and one to get their orders.
Sorry for the late jump in. Steve pretty much called it. Coronium has a focused use case, that generally is not easily expanded on. It’s meant to be “easy-bake” for less server inclined.
Additionally, Steve’s suggestion about breaking up the orders from the users is the way to go. Data objects (as opposed to User objects) have more flexibility. Just add the userid to the order record.
Thanks to both of you guys for your help. I managed to create a new object record, then grab that record and update the user record with that info.
The only question I have left is how do I get a user’s ID? mc:getMe()? mc:getUser()? some of the functions I see such as getUser asks for a userId but I actually want to FIND what the userID is… :getUser( userId, callback )
From the Coronium documentation:
getMe
:getMe( callback )
Returns the currently logged in user.
If you supply a callback to the getMe method you should have the user information returned which will have the userId you are looking for. Then just store it locally for later recall.
Done! Phew… took the scenic route but that all worked out great in the end. You guys are legends!!!
One last questions - all my user orders will be stored in the “orders” object class… I imagine (and I hope) there will be 1000s of orders each with a unique userID. Is there a limit as to how many I can store in this one class?
Thanks!
That is awesome to hear. I have found that Chris did a great job of making Coronium very flexible. You just have to look under the hood a bit and get your hands dirty.
As for your limit question, the answer to that is “it depends”. Theoretically you have no limit as long as the size of any one document does not exceed 16MB. But remember that the Database/Collection is limited by your server constraints. For example, in my setup I wasn’t satisfied with having a single MongoDB instance so I moved it to its own set of servers that are fully replicated. Later when needed I can shard the data to make it more accessible or at any time add another server to the cluster. This, of course, requires reconfiguring Coronium. I did this so I could scale on demand by just throwing more resource where it is specifically needed API side or DB side.
I would say for most app instances my setup is overkill and that a single Coronium instance should suffice. I did mine the way I did because I would rather have way more resource than I need and not have to scramble to handle an unexpected load to my infrastructure. If you are concerned about scaling and lack the skill set or resources to modify Coronium to handle it, then I would highly suggest using a third-party rather than trying to creating your own infrastructure.