How to override id generation using ottoman v2?

Hi,

I am using the following link https://v2.ottomanjs.com/ and i am wonder how to override or use my own id value instead of letting ottoman generate an id for me.

Any documentation or example would be helpful.

Thanks in advance.

Hello Clive,

Did you try passing in Model Options for instance in your model
const User = model('User', schema, { idKey: 'yourid' });

since your are using v2 version, just curious how you came to know about it ?

Yup, i tired using the ModelOption but came back with a weird error, “DocumentNotFoundError: document not found”. Below is the example i was playing around.

const User = ottoman.model("User", {
    firstName: String,
    lastName: String,
    email: String,
    tagline: String,
  },
  { idkey: "id" }
);

const perry = new User({
  id: "a1",
  firstName: "Perry",
  lastName: "Mason",
  email: "perry.mason@acme.com",
  tagLine: "Who can we get on the case?",
});

await perry.save();

A representative from your company responded to our questions and link us up on this ottomanv2.

Thank you @Clive for the feedback. Ottoman is still in alpha, I am going to take this feedback to team so that they can look into it. Please keep providing us with your feedback.

@Clive this should be fixed, you can now pass an Id like we discussed and it should work. I tried it myself.

Can you pull down alpha 6 and try ?

Yup, alpha 6 is working as intended. Thanks! :grinning: