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.
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.
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.
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.
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.
You can use easily:
.find({ "_id" : CSUUID("E3E45566-AFE4-A564-7876-AEFF6745FF")})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With