Home > Database > MongoDB > body text

How to generate ObjectID in MongoDB?

WBOY
Release: 2023-08-24 12:01:07
forward
1864 people have browsed it

How to generate ObjectID in MongoDB?

To generate ObjectID, use the following syntax in MonogDB shell −

new ObjectId()
Copy after login

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")
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template