MongoDB-এ ডকুমেন্ট থেকে _id ফিল্ড বাদ দেওয়ার জন্য প্রজেকশনে _id: 0 সেট করুন।
নমুনা ডেটা তৈরি
> db.returnDocumentWithoutObjectId.insertOne({"Name": "Carol", "Age": 25});
> db.returnDocumentWithoutObjectId.insertOne({"Name": "Sam", "Age": 21});
> db.returnDocumentWithoutObjectId.insertOne({"Name": "John", "Age": 23});
সাধারণ ফাইন্ড কোয়ারি (ObjectId সহ)
> db.returnDocumentWithoutObjectId.find();
আউটপুট:
{ "_id": ObjectId("..."), "Name": "Carol", "Age": 25 }
{ "_id": ObjectId("..."), "Name": "Sam", "Age": 21 }
{ "_id": ObjectId("..."), "Name": "John", "Age": 23 }
ObjectId বাদ দিয়ে কোয়ারি
> db.returnDocumentWithoutObjectId.find({}, {_id: 0});
আউটপুট:
{ "Name": "Carol", "Age": 25 }
{ "Name": "Sam", "Age": 21 }
{ "Name": "John", "Age": 23 }