Why not populate data using findByName? , FindById working Fine

I use Ottoman V2 in below :

Why not populate data using findByName . below I define schema

Company model

const companySchema = new Schema({
createDate: { type: String, default: new Date() },
companyName: String, 
website: String, 
bankDetails: { type: Bank, ref: "Bank" }
});
  companySchema.index.findByName = { by: 'companyName', type: 'refdoc' };
  module.exports = connection.model("Company", companySchema);

Bank model

  const bankSchema = new Schema({
  accountNo: String,
  bankName: String,
  IFSCCode: String,
  branchCode: String 
  });
  module.exports = ottoman.model("Bank", bankSchema);

Saved Data in Couchbase

         function Save(){
          var bank = new Bank({
                    accountNo: "3232323322",
                    bankName: "SBI",
                    IFSCCode: "SBIN005564",
                    branchCode: "002"
                });
                await bank.save();               
         var company = new Company({
        "companyName":"NIK",
        "website":"nik.com",
        "bankDetails":bank.id
        })
        await company .save(); 
        }

Fetch Data By Ref ID

      company ref ID : ddd312dd-ffff-4ded-9e87-e9faf4ce0534
      
        const options = { consistency: SearchConsistency.LOCAL }; 
        const result = await Company.findById("ddd312dd-ffff-4ded-9e87-e9faf4ce0534",populate: '*' });
        
       Ans : This I get proper Data 
       { 
"website": "nik.com", 
"companyName": "NIK",
"bankDetails": {
    "accountNo": "356565656565656",
    "bankName": "SBI",
    "IFSCCode": "SBIN0000049",
    "branchCode": "0221136565",
    "type": "Bank",
    "_scope": "_default",
    "id": "df013437-89c9-485d-af43-d0d239cd9b3a"
  },
  "type": "Company",
  "_scope": "_default",
  "id": "ddd312dd-ffff-4ded-9e87-e9faf4ce0534"
  }

BUT
My issue is when I populate data from findByName then I following, Why not populate I can’t understand?
please suggest to me where I was wrong.

const result = await Company.findByName(“NIK”,{populate: ’ ’ })
OR
const result = await Company.find({companyName:“NIK”},{populate: ’
’ })

        this is result
        
        { 
"website": "nik.com", 
"companyName": "NIK",
"bankDetails":"df013437-89c9-485d-af43-d0d239cd9b3a",
"type": "Company",
"_scope": "_default",
"id": "ddd312dd-ffff-4ded-9e87-e9faf4ce0534"

}

Hello @Nikhil_Bharambe did you try refdoc Index thats the solution for what you are describing. findById is a wrapper around KV operation, if you need uniqueness on a particular field you will have to use ref-doc Index

Yes tried and got solutions, Thank you so much for replying .

Solutions is given below,

const result = await Company.findByName(“NIK”)
await result.populate(‘bankDetails’)

(*) to retrieve every populable field in the document

const result = await Company.findByName(“NIK”)
await result.populate(’*’)

Glad it helped you ! You can visit our Issues to ask more questions about Ottoman.