I have one collection and in that collection there is no primary key id but there is _id. how can i add one more field to the collection as primary key id
Asked
Active
Viewed 350 times
1
-
Can you clarify your question by updating it to show a specific example of what you're looking for? – JohnnyHK Nov 22 '18 at 15:16
-
Hi, the field _id into documents is de primary key per defect in MongoDB. If you need to update one or more documents you can use db.collection.update https://docs.mongodb.com/manual/reference/method/db.collection.update/#db.collection.update Only requires that you define a query to filter and define the json with new values. – Maxi Schvindt Nov 22 '18 at 21:40
1 Answers
1
_id
is the primary in mongodb. See also Difference between “id” and “_id” fields in MongoDB

smonkey
- 195
- 2
- 7