基本使用
insertOne
- 新增單筆
// ...略
interface User {
name: string;
age: number;
gender: "male" | "female";
}
const collection: Collection<User> = db.collection<User>("user");
let { insertedId } = await collection.insertOne({
name: "Fred",
age: 27,
gender: "male",
});
insertMany
- 新增多筆
interface User {
name: string;
age: number;
gender: "male" | "female";
}
const collection: Collection<User> = db.collection<User>("user");
let { insertedId } = await collection.insertOne([
{
name: "Fred",
age: 27,
gender: "male",
},
{
name: "Chichi",
age: 26,
gender: "female",
}
]);