bwgjoseph / mongoose-vs-ottoman

feature comparison between mongoose and ottoman
0 stars 1 forks source link

support for options for create/createMany #76

Closed bwgjoseph closed 3 years ago

bwgjoseph commented 3 years ago

Hi,

Possible to consider supporting options for create? At the moment, I have a use case to return selected fields after creation.

const data = { some: 'json', doc: 'ment' }
const doc = Model.create(data, { select: 'id, doc', lean: true });

// doc
// because only selected 'id, doc' field, `some` won't be returned
{
  id: '12345',
  doc: 'ment'
}

As for createMany, this would be dependent on #68, if createMany extension gets supported, then I think it should also support options`

// sample of what CreateOptions can have right now, could have more
interface CreateOptions {
  select?: ISelectType[] | string | string[];
  lean?: boolean,
  raw?: boolean,
}

// API
create(doc: Doc, options?: CreateOptions);
createMany(docs: Doc[] | Doc, options?: CreateOptions): Promise<ManyQueryResponse>;

If this is accepted, then we maybe need to think if update/replace/remove etc should also provide such option as well

Thanks


To further add on to this, findById supports passing in options which includes select option, and hence, I could do

findById('12345', { select: 'id, name' })

But the rest of the *ById methods does not provide the options to do so

AV25242 commented 3 years ago

The way create works today is not that it does a select, it basically appends the Id that gets returned back upon save to the document that you had passed in to return the whole document back.

Probably for your use case you might want to call findById with the select options passed in after create. I will keep this in our backlog as an item to discuss and probably revisit this after we go GA. At present I see this as a nice to have.

bwgjoseph commented 3 years ago

Calling findById after create is actually 2 separate calls which I hope to avoid. Keeping this as a backlog is fine at this moment, as I don't have a very strong use-case yet

However, for the 2nd part of the question is why does it other *ById methods don't allow the options like findById to pass in like select?

AV25242 commented 3 years ago

@bwgjoseph on your last comment 2nd part I think we already discussed it here on the first part of the question, provide ability to select from a create. Can you close this ticket and create a new one and tag it as Backlog please ? It will keep the ticket cleaner for future reference