search

Home  >  Q&A  >  body text

javascript - mongo database retrieval problem

Every person in the database has the same attribute, which is the department. I want to get all the departments that appear in the database (no duplication). For example, there are 4 people in the database. No. 1 is the marketing department and No. 2 is sales. Department No. 3 is the office and No. 4 is the marketing department
Then the array I need is ['Marketing Department', 'Sales Department', 'Office']. How can I get this array? I use node.js mongose ​​mongodb in the background.

巴扎黑巴扎黑2791 days ago414

reply all(1)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-18 10:50:51

    For reference:

    db.collection.distinct()

    https://docs.mongodb.com/manu...

    I’m thinking that it might be more efficient if I check the official documentation myself: http://docs.mongodb.org/manual/.

    Love MongoDB! Have fun!


    The 2017 MongoDB Chinese Community Beijing User Group Conference is coming soon, June 3, 2017 13:00-18:00

    Many wonderful sharings! Worth participating!

    For details, please follow the "MongoDB Chinese Community" official account.

    reply
    0
  • Cancelreply