英文:
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.
this.container.items
.create<Session>(session)
.then(() => callback(null))
.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:
interface Session {
id: string;
// other properties
}
let session: Session = {
id: "myId",
// other properties
};
this.container.items
.create<Session>(session)
.then(() => callback(null))
.catch((error) => callback(error));
英文:
The id
is specified in the object, in your case, the session
object:
interface Session{
id: string;
// other properties
}
let session : Session = {
id: "myId",
// other properties
};
this.container.items
.create<Session>(session)
.then(() => callback(null))
.catch((error) => callback(error));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论