Deniz
Deniz

Reputation: 1511

Fastest Way to (1) not insert duplicate entry (2) consolidate duplicates in Mongo DB?

(1) What's the fastest way to check if an item I'm about to "insert" into a MongoDB collection is unique (and if so not insert it)

(2) For an existing database, what's the fastest way to look at all the entries and remove duplicates but keep one copy i.e. like a "set" function: {a,b,c,a,a,b} -> {a,b,c}

Thanks!

Upvotes: 0

Views: 833

Answers (1)

user2665694
user2665694

Reputation:

(1) Create a unique index on the related columns and catch the error upon insertion time

Upvotes: 2

Related Questions