Class GraphDBModel

Create a document based on the model. Note: The constructor does not comply OOP since it is dynamically generated. Same as GraphDBModel.createDocument

Name

GraphDBModel

Param

The data / properties in the new document

Returns

Hierarchy

  • GraphDBModel

Constructors

Properties

externalKey2Option: Map<any, any>
internalKey2Option: Map<any, any>
nestedType2Model: Uri2ModelMap
preloaded: boolean = false
schema: {}

Type declaration

    schemaOptions: SchemaOptions

    Methods

    • Private

      Remove fields that are not in the schema. Directly mutate the data object.

      Parameters

      • data: object

      Returns object

    • Create a document based on the model. Identical to Model(data)

      Parameters

      • data: object

        The data / properties in the new document

      • Optional options: {
            uri?: string;
        }
        • Optional uri?: string

      Returns GraphDBDocument

    • Find documents from the model.

      Member Of

      Example

      // Find all documents for this model
      await Model.find({});

      // Find with filter
      await Model.find({first_name: "Lester"});

      // Find with nested filter
      await Model.find({primary_contact: {first_name: "Lester"}});

      // Find with array filter, currently only supports $in
      await Model.find({hobbies: {$in: ['coding', 'jogging']}});

      // Find with compare filter, supports $le, $lt, $ge, $gt
      await Model.find({age: {$lt: 100, $gt: 20}}); // less than 100 and greater than 20

      await Model.find({age: {$le: 100, $ge: 20}}); // less or equal to 100 and greater or equal to 20

      // Find all documents with populates, support nested populates.
      await Model.find({}, {
      populates: [
      'primary_contact', // Populate primary_contact
      'organization.primary_contact' // Populate organization and organization.primary_contact
      ]
      });

      // Find all clients where the characteristic_14 contains 'le' and characteristic_15='lyu'
      await GDBClientModel.find({
      characteristicOccurrences: {
      $and: [
      {occurrenceOf: ":characteristic_14", dataStringValue: 'lester'},
      {occurrenceOf: ":characteristic_15", dataStringValue: 'lyu'}
      ]
      }
      });

      Parameters

      • filter: {}
        • Optional options: {
              ignoreTransaction?: boolean;
              populates?: any;
          } = {}
          • Optional ignoreTransaction?: boolean
          • Optional populates?: any

        Returns Promise<GraphDBDocumentArray>

        The found documents.

      • Find all documents matched to the filter and delete.

        Member Of

        Example

        // Find all documents have primary_contact.first_name equal to 'Lester' and delete them.
        const doc = await Model.findAndDelete({primary_contact: {first_name: 'Lester'}});

        Parameters

        • filter: {}

          The filter.

          • Optional options: {
                ignoreTransaction?: boolean;
            }
            • Optional ignoreTransaction?: boolean

          Returns Promise<GraphDBDocumentArray>

          • The deleted Documents.
        • Find a document by ID in the model.

          See

          find for further information

          Example

          // Same as
          (await Model.find({_id: id}, {populates}))[0];

          // Find one document with _id = 1 and populate
          Model.findById(1, {populates: ['primary_contact']});

          Parameters

          • id: string | number

            ID of the document, usually represents as _id

          • Optional options: {
                ignoreTransaction?: boolean;
                populates?: any;
            }
            • Optional ignoreTransaction?: boolean
            • Optional populates?: any

          Returns Promise<GraphDBDocument>

        • Find one document by ID and delete it.

          Example

           // Find one document has id 1 and delete it.
          const doc = await Model.findByIdAndDelete(1);

          Parameters

          • id: string | number

            The identifier

          • Optional options: {
                ignoreTransaction: boolean;
            }
            • ignoreTransaction: boolean

          Returns Promise<GraphDBDocument>

          • The deleted document.
        • Find one document by ID and update

          Example

          // Find a document has id = 1 and update the primary_contact.first_name to 'Lester'
          const doc = await Model.findByIdAndUpdate(1, {primary_contact: {first_name: 'Lester'}});

          Parameters

          • id: string | number

            The identifier

          • update: {}

            The Update to the found document

            • Optional options: {
                  ignoreTransaction?: boolean;
              }
              • Optional ignoreTransaction?: boolean

            Returns Promise<GraphDBDocument>

          • Find a document by URI in the model.

            See

            find for further information

            Example

            // Same as
            (await Model.find({_uri: uri}, {populates}))[0];

            // Find one document with _uri = "http://example/1" and populate
            Model.findByUri("http://example/1", {populates: ['primary_contact']});

            Parameters

            • uri: string

              ID of the document, usually represents as _id

            • Optional options: {
                  ignoreTransaction?: boolean;
                  populates?: any;
              }
              • Optional ignoreTransaction?: boolean
              • Optional populates?: any

            Returns Promise<GraphDBDocument>

          • Find one document by URI and delete it.

            Example

             // Find one document has uri "http://example.com/person/1" and delete it.
            const doc = await Model.findByUriAndDelete("http://example.com/person/1");

            Parameters

            • uri: string

              The identifier

            • Optional options: {
                  ignoreTransaction: boolean;
              }
              • ignoreTransaction: boolean

            Returns Promise<GraphDBDocument>

            • The deleted document.
          • Find one document by URI and update

            Example

            // Find a document has uri = "http://example.com/person/1" and update the primary_contact.first_name to 'Lester'
            const doc = await Model.findByUriAndUpdate("http://example.com/person/1", {primary_contact: {first_name: 'Lester'}});

            Parameters

            • uri: string

              The unique identifier

            • update: {}

              The Update to the found document

              • Optional options: {
                    ignoreTransaction?: boolean;
                }
                • Optional ignoreTransaction?: boolean

              Returns Promise<GraphDBDocument>

            • Find one document in the model.

              See

              find for further information

              Example

              // Same as
              await (Model.find(filter, {populates}))[0];

              // Find one document and populate
              Model.findOne({age: 50}, {populates: ['primary_contact']});

              Parameters

              • filter: {}

                The filter

                • Optional options: {
                      ignoreTransaction?: boolean;
                      populates?: any;
                  }
                  • Optional ignoreTransaction?: boolean
                  • Optional populates?: any

                Returns Promise<GraphDBDocument>

              • Find one document matched to the filter and delete.

                Example

                // Find one document have primary_contact.first_name equal to 'Lester' and delete it.
                // The document with smaller id will be deleted if found multiple documents.
                const doc = await Model.findOneAndDelete({primary_contact: {first_name: 'Lester'}});

                Parameters

                • filter: {}

                  The filter *

                  • Optional options: {
                        ignoreTransaction: boolean;
                    }
                    • ignoreTransaction: boolean

                  Returns Promise<undefined | GraphDBDocument>

                  • The deleted document.
                • Find one document and update.

                  Example

                  // Find a document has _id = 1 and update the primary_contact.first_name to 'Lester'
                  // The document has smaller id will be updated if it finds multiple matched documents.
                  const doc = await Model.findOneAndUpdate({_id: 1}, {primary_contact: {first_name: 'Lester'}});

                  Parameters

                  • filter: {}

                    The filter

                    • update: {}

                      The Update to the found document

                      • Optional options: {
                            ignoreTransaction?: boolean;
                        }
                        • Optional ignoreTransaction?: boolean

                      Returns Promise<GraphDBDocument>

                    • Generate creation query.

                      Parameters

                      • uri: string
                      • data: any

                      Returns Promise<{
                          footer: string;
                          header: string;
                          innerQueryBodies: string[];
                          instanceName: string;
                          queryBody: string;
                      }>

                    • Private

                      Generate delete query of a document.

                      Parameters

                      Returns {
                          query: string;
                          where: string[];
                      }

                      • query: string
                      • where: string[]
                    • Private

                      Parameters

                      • filter: any
                      • config: {} = {}

                        Returns {
                            construct: array;
                            query: string;
                            where: array;
                        }

                        • construct: array
                        • query: string
                        • where: array
                      • Private

                        Get all path from the current model

                        Returns string[]

                      Generated using TypeDoc