Thank you… but unfortunately db.collection.find() has no solution. I already mentioned in my queries. though I create a function and got the result, not exactly with the value but by some other way.
Many thanks for your time, contribution and support, but it doesn’t meet the requirement. I am getting below result:
{
Item_qnty: 0
}
{
Item_qnty: 10
}
I dont want KEY “Item_qnty” I only want value 0,10,6 nothing else
Sir, as I mentioned in earlier reply to someone else that I wrote a function and achieve whatever I want. I didnot get exactly the value of a Key but the end goal has been achieved. I need value to keep in loop and deduct the same from another value. Below code is working fine for me and my requirement: const currDate = new Date();
// Array of collection names
const collectionNames = db.getCollectionNames();
// Iterate over each collection
for (const collectionName of collectionNames)
{
const collection = db.getCollection(collectionName);
// Get documents with retention_days field
const documents = collection.find({ retention_days: { $exists: true } });
// Iterate over each document
documents.forEach (document =>
{
const retentionDays = document.retention_days;
const watermark = new Date(currDate.getTime() - (retentionDays));
all_insts = [collectionName] + list(collectionName.descendants)
for (inst in all_insts)
{
log.info('enforcing retention for institution %s', inst.id)
users = User.find_by_iid(inst.id);
}
/* // gather up user id's and notify once
notify_user_ids = set();
for (user in users) {
log.info('enforcing retention for user %s', user._id);
}
*/
// Perform further operations with the watermark
// ...
});
}
your code also gave me nearly requested output as below:
{
_id: null,
retention_days: [
10,
0
]
}