© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
j
stuff ;)
I am sorry, I am not sure if I understand what mean. do you need to group/aggregate it?
docs.mongodb.com/manual/reference/operator/aggreg…
like this? because you only want to see the unique users inside of the array?
Dev ashish Vats
i want to sort an array on the basis of its length
Dev ashish Vats which length? the length of characters of the userId field? or you mean by index?
please explain what length means for you. :) all userIds in your example have 24 characters all other ids have 24 characters.
do you mean you want to sort them by the length of the invite array?
do you mean docs.mongodb.com/manual/reference/operator/aggreg… ?
In mongodb, we have collections like above , now i have to sort intive on the basis of its length
so you mean sortByCount? docs.mongodb.com/manual/reference/operator/aggreg… which sorts by the amount of items in a certain datastructure. in your case that is an array?
db.<your-collection>.aggregate( [ { $sortByCount: "$invites" } ] );
this is a blind example since I don't have your dataset.
something like that? check the mongodb documentation link I've linked. And let me know if I still misunderstood you :)