如何在MongoDB中生成ObjectID?
要生成ObjectID,请在MonogDBshell中使用以下语法-
new ObjectId()
让我们实现以上语法以在MongoDB中生成ObjectID-
> new ObjectId()ObjectId("5cd7bf2f6d78f205348bc646") > new ObjectId()ObjectId("5cd7bf316d78f205348bc647") > new ObjectId()ObjectId("5cd7bf336d78f205348bc648") > new ObjectId()ObjectId("5cd7bf346d78f205348bc649") > new ObjectId()ObjectId("5cd7bf356d78f205348bc64a") > new ObjectId()ObjectId("5cd7bf396d78f205348bc64b") > new ObjectId()ObjectId("5cd7bf3a6d78f205348bc64c")
如上所示,每次您将获得一个新的ObjectId。