Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • MongoDB Get names of all keys in collection

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 10.5k
    Comment on it

    Hello All,

    In this blog we will discuss about how to get all keys in mongoDb collection.

    Sometimes we are in a situation in which we want only the keys not the data itself from the collection.

    So as a result you can try by following below code to fetch the keys:

    Syntax-

    var dataKeys = db.collection.findOne();
    
    for (var key in dataKeys) { print (key) ; }
    

    Example-

    > var data = db.keytags.findOne();
    
    > for (var key in data) { print (key) ; }
    

    Output-

    > for (var key in data) { print (key) ; }
    __;v
    _id
    additionalProperties
    businessId
    clientId
    createdAt
    creatorAccountId
    dataChecksum
    deleted
    domain
    donotIndex
    isDomainCard
    kiTAG
    lastIndexedOn
    manualUpdate
    name
    relatedKeywords
    seo
    status
    title
    type
    updatedAt
    > 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: