U
U
Urukhayy2017-07-07 10:42:45
MongoDB
Urukhayy, 2017-07-07 10:42:45

Is it possible to use text sentences as an identifier in the database?

There is an application running on MEAN-stack. Suppose that in the database (Mongo) of this application there is a collection "people" that has several fields: age, gender, dates. And in this collection there is a first name field, which is unique. In this field, in full form, enter the first name, last name and patronymic, separated by spaces. Can this field be used as an identifier, for example, when deleting a document from a collection?

db.collection.remove({FIO: "Иванов Иван Иванович"});

But there is a problem, if a person makes a typo in a line, deletion may not work.
Mongo has long _id of random characters with automatic generation, but the JSON-query for deletion can be formed by a person, and it is not very convenient to use long id of random characters.
Or is it still the right decision to send these _id to the front-end, and then accept it back with a deletion request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Wolf, 2017-07-07
@Urukhayy

Is it possible to use text sentences as an identifier in the database?
It is quite possible and sometimes even necessary to delete a record/line/ document not by ID, but by the value of one of the fields (Are you asking this?) Another issue is that an ID is a unique record that uniquely identifies a certain string/record/document, both in MongoDB and in SQL databases. In other words, when deleting by ID, you unequivocally delete a specific record, but in the case of deletion by some other parameter, this parameter may coincide with another record/document, and it is far from certain that you will delete what you wanted.
Mongo has auto-generated long _id random characters, but I don't want to use them for that purpose
The main thing is that you don’t touch the very logic of generating and positioning the ID, it may come in handy more than once in the future, and you can delete records / documents, if you wish, using any of the fields convenient for you. For example, you can add your own field to the document with the name "id" , enter whatever you like / conveniently there, and identify and delete documents by this field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question