MST

星途 面试题库

面试题:MongoDB Shell中如何对集合进行插入多条文档操作

假设你有一个名为`students`的集合,需要向其中插入多条学生信息文档,每个文档包含`name`(字符串类型)、`age`(数字类型)和`scores`(数组类型,包含学生各科成绩),请用MongoDB Shell编写实现代码。
22.4万 热度难度
数据库MongoDB

知识考点

AI 面试

面试题答案

一键面试
var studentsToInsert = [
    { name: "Alice", age: 20, scores: [85, 90, 78] },
    { name: "Bob", age: 21, scores: [70, 80, 85] },
    { name: "Charlie", age: 19, scores: [92, 88, 95] }
];

db.students.insertMany(studentsToInsert);