CosmosDB 插入具有特定 ID 的项

huangapple go评论105阅读模式
英文:

CosmosDB insert item with specific ID

问题

在插入新对象到Cosmos DB时是否可以指定ID?

英文:

I was wondering if it is possible to specific the ID when inserting a new object on Cosmos DB.

  1. this.container.items
  2. .create<Session>(session)
  3. .then(() => callback(null))
  4. .catch((error) => callback(error));

Is it possible to specify the ID when inserting it?

答案1

得分: 2

The id is specified in the object, in your case, the session object:

  1. interface Session {
  2. id: string;
  3. // other properties
  4. }
  5. let session: Session = {
  6. id: "myId",
  7. // other properties
  8. };
  9. this.container.items
  10. .create<Session>(session)
  11. .then(() => callback(null))
  12. .catch((error) => callback(error));
英文:

The id is specified in the object, in your case, the session object:

  1. interface Session{
  2. id: string;
  3. // other properties
  4. }
  5. let session : Session = {
  6. id: &quot;myId&quot;,
  7. // other properties
  8. };
  9. this.container.items
  10. .create&lt;Session&gt;(session)
  11. .then(() =&gt; callback(null))
  12. .catch((error) =&gt; callback(error));

huangapple
  • 本文由 发表于 2023年2月16日 03:04:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定