Moralis.Objectcontains key-value pairs of JSON-compatible data. This data is schemaless, which means that you don’t need to specify ahead of time what keys exist on each
Moralis.Object. You simply set whatever key-value pairs you want, and our back-end will store it.
Moralis.Objectis an instance of a specific subclass with a class name that you can use to distinguish different sorts of data. For example, we could call the object a
LegendaryMonster. We recommend that you NameYourClassesLikeThis and nameYourKeysLikeThis, just to keep your code looking pretty.
Moralis.Querywill return instances of the new class for any
Moralis.Objectwith the same classname. If you’re familiar with
Backbone.Model, then you already know how to use
Moralis.Object. It’s designed to be created and modified in the same ways.
new Moralis.Object(className)will create a single Moralis Object with that class name.
extends, the SDK is not automatically aware of your subclass. If you want objects returned from queries to use your subclass of
Moralis.Object, you will need to register the subclass, similar to what we do on other platforms.
signUpwill return the subclass
CustomUser.signUpwill return the subclass
Monsterdescribed above to the Moralis Cloud. The interface is similar to a
Backbone.Model, including the
Monsterbefore running this code. Your Moralis app lazily creates this class for you when it first encounters it.
objectIdis a unique identifier for each saved object.
updatedAtrepresent the time that each object was created and last modified in the cloud. Each of these fields is filled in by Moralis, so they don’t exist on a
Moralis.Objectuntil a save operation has been completed.
Moralis.Objectas the value of a property in another
Moralis.Object. By default, when you call
save()on the parent object, all nested objects will be created and/or saved as well in a batch operation. This feature makes it really easy to manage relational data as you don’t have to take care of creating the objects in any specific order.
falsemay be useful:
contextdictionary that is accessible in cloud code
afterSavetriggers for that
Moralis.Object. This is useful if you want to condition certain operations in cloud code triggers on ephemeral information that should not be saved with the
Moralis.Objectin the database. The context is ephemeral in the sense that it vanishes after the cloud code triggers for that particular
Moralis.Objectas it has been executed. For example:
Moralis.Objecthas been uploaded to the server, you can use the
objectIdto retrieve it using a
Moralis.Object, use the
attributesproperty of the
fetchmethod like so:
increment. When no amount is specified, 1 is used by default.
addappend the given object to the end of an array field.
addUniqueadd the given object only if it isn’t already contained in an array field. The position of the insert is not guaranteed.
removeremove all instances of the given object from an array field.
savein between every different kind of array operation.
Postobject may have many
Commentobjects. Moralis supports all kinds of relationships, including one-to-one, one-to-many, and many-to-many.
Moralis.Objectas a value in the other object. For example, each
Commentin a blogging app might correspond to one
Postwith a single
Comment, you could write:
objectId's like so:
Moralis.Object's are not fetched. These objects’ values cannot be retrieved until they have been fetched like so:
Moralis.Relation. This works similar to storing an array of
Moralis.Object's in a key, except that you don’t need to fetch all of the objects in a relation at once. In addition, this allows
Moralis.Relationto scale to many more objects than the array of
Moralis.Objectapproach. For example, a
Usermay have many
Poststhat she might like. In this case, you can store the set of
relation. In order to add a
Postto the “likes” list of the
User, you can do:
removemultiple times before calling save:
query. The code looks like:
Moralis.Query, please look at the Queries portion of this guide. A
Moralis.Relationbehaves similar to an array of
Moralis.Objectfor querying purposes, so any query you can do on an array of objects, you can do on a
Moralis.Object. Moralis also supports
null. You can nest
JSON Objects and
JSON Arrays to store more structured data within a single
Moralis.Object. Overall, the following types are allowed for each field in your object:
Moralis.Object. We recommend you use
Moralis.Fileto store images, documents, and other types of files. You can do so by instantiating a
Moralis.Fileobject and setting it on a field. See Files for more details.