Search code examples
javascriptparse-platformparse-server

Get all keys in a class in Parse-Server


I'm writing a global search function (JS & Cloud Code), and I need to get all the available keys from a given class.

I tried extending a class and getting its object attributes

var Item = Parse.Object.extend("Item");
var item = new Item();
console.log(item.attributes);

But I'm getting an empty object.

If I retrieve an object from the database, either by get() or find(), I do get its keys, but only those which have values, and I need to retrieve all the keys in a given class.


Solution

  • I figured it out! I can query the Schema of a class

    var itemSchema = new Parse.Schema('Item');
    itemSchema.get({
        success: function(schema) {
    
        },
        error: function(object, error) {
    
        }
    });
    

    And even get the schema of all my classes

    Parse.Schema.all({
        success: function(schemas) {
    
        },
        error: function(object, error) {
    
        }
    });
    

    Hope this answer helps someone someday!