CenterForDigitalHumanities / TPEN-services

Services required by TPEN interfaces in order to interact with data
1 stars 0 forks source link

Mongo Controller 'getById()` #107

Open thehabes opened 4 months ago

thehabes commented 4 months ago

Currently implemented as

/**
 * Get by ID.  We need to decide about '@id', 'id', '_id', and http/s 
 */
async getByID(id) {
    return await this.find({ "_id": id })
}

It has an error right now because this object does not have a type or @type associated with it. In our mongo database we have multiple collection. In order to know which objects go into which collections, we match on the value of the objects type. If no type is present, a collection cannot be discerned and so an error is returned.

cubap commented 4 months ago

With just 3, there must be a way to get this managed at a lowish cost.

  1. Absolute non-circular disambiguation: Given Groups, Users, and Projects... we can know that groups.members and projects.group so with a max of two checks, we can know what it is.
  2. Brute force: There are only 3 collections so we can run a script that just runs a do-while for each collection.findOne() until it isn't null.
  3. Specialization: The driver can be changed to require a second argument identifying the collection. This causes a problem of pairing the MongoDB API with our logic, but this could similarly be useful as a table name in a relational database.
cubap commented 4 months ago

Best solution preferred by all present is (3) as an optional parameter (pass the collection when it is known) and fall back to (1) when collection/table is not known.

cubap commented 1 month ago

Also to consider here, the find() is an array and getById() should always be singular. Either we need to implement findOne() or flatten away the array before we return the result.