MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

How to sample unique documents in a collection

Hi Team,

As part of sampling, if I have 10000 documents with different sampling of data. In order to find unique documents with their data type. How do I find it in compass or any MongoDB query available.

Example:

db.collection_001.drop();
db.createCollection(“collection_View_Aggregation_042”);
db.collection_001.insert(
{
   “_id” : 1,
   “item” : “”,
   “price” :
});

db.collection_001.insert(
{
   “_id” : ,
   “item” : “”,
   “price” : ,
   “quantity” :
});

db.collection_001.insert(
{
   “_id” : ,
   “item” : “”,
   “price” : ,
   “quantity” : ,
   “date” : ISODate(“2014-01-01T08:15:39.736Z”)
});

Increasing to 10000 documents ith different data type. In order to find unique documents from these collection is very difficult.

How do i fetch unique document name along with data type? Is any shortcut available?

w
Thanks & Regards,
Jay

To be precise, I have 1000 documents in 1 collection.
Document 1 - 10 different Field name (_id, name,dob, address,pin_code, Co-ordinates,etc.,)
Document 2 - Only 3 Field Name(_id, Name, Dob)
Document 3 - Contains 45 Field Name
Document 4 - Contains 150 Field Name
Document 5 - Contains 250 Field Name
Document 6 - Contains 200 Field Name
.
.
.
so on.

Field names may be similar or may vary from one document to other. Same is called “Sampling” in MongoDB.

If i want to find all Field name which is available in 1 Collection i have to manually verify all 1000 records. If i want to find all field with in the collection, irrespective of document, how do i find it?