如何在 mongodb 中获取插入执行时间?

How can i get the insert execution time in mongodb?

我创建了一个小的 java 项目,我试图在其中恢复插入操作的执行时间。到目前为止,我只是在没有获得执行时间的情况下将数据插入数据库。这是一个代码片段:

MongoClient client = new MongoClient("localhost:27017" , options);
MongoDatabase database = client.getDatabase("personsDB");
MongoCollection<Person> collection = database.getCollection("personColl", Person.class);

Person person = new Person("Name");
collection.insertOne(person);

有人能给我指出正确的方向吗?

谢谢!

MongoDB 得到了一个分析器,它在 system.profile 集合中记录数据。 有不同的 profiling levels:

0 - 分析器已关闭

1 - 仅针对慢速操作分析数据(默认慢于 100 毫秒)

2 - 收集所有数据库操作的分析数据。

要设置配置文件,您应该使用 db.setProfilingLevel(profiling-level) 其中 profiling-level 是上述值之一。

数据解释说明here