mongodb - Best way to return documents that include a count of an internal collection? -


I have a collection with documents, such as the following:

  {title: First, "Everything": ['Something', 'Something']}   

And I would like to get output like the following:

  {"First", 3}, {"seconds, 2}   

What's the best way to do this? I call it the map function Implemented by:

  db.coll.find (). Map (function) {return {title: Item.title, count: item.sub_items.length};}) ;   

When trying to get the above results, would I be better to use and use something to be better than a display perspective if you have MongoDB 2.6 or later < / Strong>, you can or

$ size from the document:

count The power and the total number of items in the array.

Below is an unwanted example:

  db.coll.aggregate ({{"$ project": {"Title": 1, "count": {"$ size": "$ sub_items"}}}))    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -