node.js - how to find the distinct values of a field in a MongoDB collection using Node MongoClient -


in mean application, need find distinct values of field named "datafields" collection "fixed_asset_register", using (non-mangoose) mongoclient:

var mongodb = require('mongodb');  var assert = require('assert');  var mongoclient = mongodb.mongoclient;  mongoclient.connect(url, function (err, db) {     if (err) {         console.log('unable connect mongodb server. error:', err);     } else {         console.log('connection established to', url);          var collection = db.collection('fixed_asset_register');         var distictdatafieldsvalue = ?  } 

what proper syntax distinct values of field named "datafields"?

i solved issue using collection.distinct:

collection.distinct("datafields",(function(err, docs){             console.log(docs);             assert.equal(null, err);             db.close();         })) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -