0
{
  "_id" : 654321,
  "first_name" : "John",
  "last_name" : "Doe",
  "interested_by" : [ "electronics", "sports", "music" ],
  "address" : {
    "name" : "John Doe",
    "company" : "Resultri",
    "street" : "1015 Mapple Street",
    "city" : "San Francisco",
    "state" : "CA",
    "zip_code" : 94105
  }
}

How can i find the name of elements in array 'intersted_by' using command??

2
  • What are you asking exactly? Do you want the number of elements in the "interested_by" array or the value of that field? Commented Jul 6, 2016 at 0:12
  • I was asking for the value of that field Commented Jul 6, 2016 at 13:14

2 Answers 2

1

You can have the size of your result in the mongo shell using :

db.collection.count()

Replace collection by the name of your collection. You can also add a find condition like this :

db.collection.find().count()

Like that, you wan restrict your result with deffernts clauses before count the numbers of data corresponding

Edit : don't forget to do the command use databaseName if you're not in your database, it does'nt work

Sign up to request clarification or add additional context in comments.

Comments

0

You can count the amount of keys by doing:

var count = Object.keys(myObject).length;

1 Comment

How do I get the name 'electronics','sports' and 'music' from 'intersted_by'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.