Created
January 9, 2011 22:25
-
-
Save naholyr/772094 to your computer and use it in GitHub Desktop.
Liste des auteurs triés par nombre de livre
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = function() { | |
this.nb_books = this.books.length; | |
emit(this._id, this); | |
} | |
r = function(k,v) { | |
return v[0]; | |
} | |
db[db.authors.mapReduce(m, r).result].find().sort({nb_books:-1}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = function() { | |
emit(this._id, this.books.length); | |
} | |
r = function(k,v) { | |
var s=0; | |
for (var i=0;i<v.length;i++) s+=v[i]; | |
return s; | |
} | |
db[db.authors.mapReduce(m, r).result].find().sort({value:-1}) |
Dans la version full, on a ce type de sortie :
{ "_id" : ObjectId("4d29b0f6b75cca91684e7f1a"), "value" : { "_id" : ObjectId("4d29b0f6b75cca91684e7f1a"), "name" : "Bill", "birth" : "Tue Jan -2147483647 584555983 15:25:52 GMT+0100 (CET)", "books" : [
ObjectId("4d29b086b75cca91684e7f19"),
ObjectId("4d29b086b75cca91684e7f19")
], "nb_books" : 2 } }
{ "_id" : ObjectId("4d29b104b75cca91684e7f1b"), "value" : { "_id" : ObjectId("4d29b104b75cca91684e7f1b"), "name" : "Bill's wife", "birth" : "Tue Jan -2147483647 584555987 15:25:52 GMT+0100 (CET)", "books" : [ ObjectId("4d29b086b75cca91684e7f19") ], "nb_books" : 1 } }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exemple de sortie :
Il faut encore convertir ça en objets complets.