I am trying to get the count of followers from user table which is basically a array list using java programming.
I am using below query to get the count using command line interface.
db.userinfo.aggregate([{ $project : {followersCount : {$size: "$followers"}}}])
But I am not able to create the same query in java as I am new. Below is the code I wrote in java and I am getting com.mongodb.MongoCommandException: Command failed with error 17124: 'The argument to $size must be an array, but was of type: int' Error.
AggregateIterable<Document> elements = collectionUserInfo.aggregate(
Arrays.asList(new BasicDBObject("$project", new BasicDBObject("followers",
new BasicDBObject("$size", new BasicDBObject("followers",1).put("followers",new BasicDBObject("$ifNull", "[]")))))));
Can Anyone please help me with this