couchbaselabs / node-ottoman

Node.js ODM for Couchbase
https://ottomanjs.com/
Apache License 2.0
287 stars 98 forks source link

findOne behavior does not match documentation #785

Closed mikereiche closed 3 months ago

mikereiche commented 3 months ago

https://stackoverflow.com/questions/78838348/documentnotfounderror-in-the-findone-method-in-node-ottoman-couchbase-orm

https://ottomanjs.com/docs/basic/model

User.findOne({ name: 'Jane' });
// will return a document with a User with the name "Jane" or null in case of not finding it

https://github.com/couchbaselabs/node-ottoman/blob/4ceeda0dd62155831105cf10ed1938758980c177/src/model/create-model.ts#L247-L256

    static findOne = async (filter: LogicalWhereExpr = {}, options: FindOptions = {}) => {
      const response = await find(metadata)(filter, {
        ...options,
        limit: 1,
      });
      if (response?.rows?.length) {
        return response.rows[0];
      }
      throw new DocumentNotFoundError();
    };
hessaam commented 3 months ago

+1

mikereiche commented 3 months ago

Duplicate of #783

arabsoheyl commented 3 months ago

+1