Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skratchdot/mongodb-distinct-types
Similar to the db.myCollection.distinct() function, distinctTypes() will return "types" rather than "values"
https://github.com/skratchdot/mongodb-distinct-types
Last synced: about 2 months ago
JSON representation
Similar to the db.myCollection.distinct() function, distinctTypes() will return "types" rather than "values"
- Host: GitHub
- URL: https://github.com/skratchdot/mongodb-distinct-types
- Owner: skratchdot
- Created: 2012-05-01T02:42:06.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-04-25T04:42:00.000Z (over 10 years ago)
- Last Synced: 2024-10-19T00:24:30.513Z (3 months ago)
- Language: JavaScript
- Homepage: http://skratchdot.github.com/mongodb-distinct-types/
- Size: 133 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MongoDB - distinct-types.js #
[Project Page](http://skratchdot.com/projects/mongodb-distinct-types/)
[Source Code](https://github.com/skratchdot/mongodb-distinct-types/)
[Issues](https://github.com/skratchdot/mongodb-distinct-types/issues/)## Description: ##
Similar to the db.myCollection.distinct() function, distinctTypes() will return
"types" rather than "values". To accomplish this, it adds the following
function to the DBCollection prototype:```javascript
DBCollection.prototype.distinctTypes = function (keyString, query, limit, skip) {};
```## Usage: ##
```javascript
// we hope this would return ['bson'] not ['bson','string']
db.users.distinctTypes('name');// should return ['string']
db.users.distinctTypes('name.first');// should return ['string']
db.users.distinctTypes('address.phone');// only search documents that have { 'name.first' : 'Bob' }
db.users.distinctTypes('address.phone', {'name.first':'Bob'});// only search the first 10 documents
db.users.distinctTypes('address.phone', {}, 10);// only search documents 10-15
db.users.distinctTypes('address.phone', {}, 10, 5);
```## Caveats: ##
By design, distinctTypes() returns 'bson' rather than 'object'.
It will return 'numberlong' rather than 'number', etc.## Installation: ##
Download: [distinct-types.js](https://github.com/skratchdot/mongodb-distinct-types/raw/master/distinct-types.js)
### Option 1 ###
Add this script to your .mongorc.js file.
See: [http://www.mongodb.org/display/DOCS/Overview+-+The+MongoDB+Interactive+Shell#Overview-TheMongoDBInteractiveShell-.mongorc.js](http://www.mongodb.org/display/DOCS/Overview+-+The+MongoDB+Interactive+Shell#Overview-TheMongoDBInteractiveShell-.mongorc.js)
### Option 2 ###
Start the shell after executing this script
mongo --shell distinct-types.js