newObjectId()ObjectId("5cd7bf316d78f205348bc647")>newObjectId( )ObjectId(&"/> newObjectId()ObjectId("5cd7bf316d78f205348bc647")>newObjectId( )ObjectId(&">

Home >Database >MongoDB >How to generate ObjectID in MongoDB?

How to generate ObjectID in MongoDB?

WBOY
WBOYforward
2023-08-24 12:01:071925browse

How to generate ObjectID in MongoDB?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete