Answer the question
In order to leave comments, you need to log in
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: "Иванов Иван Иванович"});
Answer the question
In order to leave comments, you need to log in
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 purposeThe 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 questionAsk a Question
731 491 924 answers to any question