Construct count query in MongoDB -


i have mongodb database documents this:

{"users" : ["u1", "u2", "u3"]} {"users" : ["u1", "u4"]} {"users" : ["u1", "u3", "u5", "u6", "u7"]} 

i obtain count of document larger number of users. using above, query return 5 highest user count within database. how can in mongodb?

i can number of documents specific size with:

db.mydb.find({users: {$size: 5}}).count() 

however, can not figure out how find largest count within documents in user array.

thanks.

you can't directly in mongodb. however, can have field in same document called "user_count" , use $inc operator increment 1 every time add new user "users" array.

your update like:

db.mydb.update({<update_condition>}, {$push :{"users":"u8"}, $inc : {"user_count":1}}) 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -