S
S
source20032016-12-05 03:53:22
MongoDB
source2003, 2016-12-05 03:53:22

How to check all documents in a collection for uniqueness?

There is a collection with ~1kk documents of the form {_id: ObjectId, "id": "ID"}, you need to check all of them with each other to find out if all IDs are unique in this collection.
What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad_Fedorenko, 2016-12-05
@source2003

db.collection.find({}).count() must be equal to db.collection.distinct({"ID"}).length

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question