首页 文章资讯内容详情

在MongoDB中如何获取保存的对象?

2026-06-04 1 花语

让我们首先创建一个变量。以下是查询-

> var studentDetails={"StudentFirstName":"Chris","StudentLastName":"Brown","StudentAge":24};

以下是使用save()保存记录的查询-

> db.demo45.save(studentDetails); WriteResult({ "nInserted" : 1 })

在find()方法的帮助下显示集合中的所有文档-

> studentDetails;

这将产生以下输出-

{ "StudentFirstName" : "Chris", "StudentLastName" : "Brown", "StudentAge" : 24, "_id" : ObjectId("5e25dab4cfb11e5c34d898ec") }