Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a guid in a mongodb shell query

When using the MongoDB shell, how do I use a guid datatype (which I have used as the _id in my collection).

The following format doesn't work:

>db.person.find({"_id","E3E45566-AFE4-A564-7876-AEFF6745FF"}); 

Thanks.

like image 274
Journeyman Avatar asked Apr 13 '11 15:04

Journeyman


People also ask

What is GUID MongoDB?

GUIDs are often being used to identify custom objects created in software. Software developers very often explicitly store those identifiers in the database and do not rely on identifiers generated by the database system. MongoDB and the MongoDB drivers come with built-in support for the GUID/UUID data type.

How does shell script connect to MongoDB?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.

Does MongoDB support UUID?

MongoDB has built-in support for the UUID data type and most of the MongoDB drivers support UUID natively. MongoDB itself stores UUIDs as Binary fields and when such Binary fields are accessed from software, MongoDB drivers usually convert their value as found in the database to language-specific UUID or GUID objects.

Does MongoDB Compass have a shell?

Starting in version 1.22, MongoDB Compass contains an embedded shell, mongosh . mongosh is a JavaScript environment for interacting with MongoDB deployments. You can use mongosh to test queries and operations in your database.


Video Answer


1 Answers

You can use easily:

.find({ "_id" : CSUUID("E3E45566-AFE4-A564-7876-AEFF6745FF")}) 
like image 144
Edward Weinert Avatar answered Sep 23 '22 23:09

Edward Weinert