To generate ObjectID, use the following syntax in MonogDB shell −
new ObjectId()
Let us implement the above syntax to generate ObjectID in MongoDB −
> 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")
As shown above, you will get a new ObjectId every time.
The above is the detailed content of How to generate ObjectID in MongoDB?. For more information, please follow other related articles on the PHP Chinese website!