Answer the question
In order to leave comments, you need to log in
Find the user id in all MongoDB documents, remove the user id from all documents, and put it in some specific one?
I need to search the database for all matches by user id, remove them from all documents, and add them to the one I need. How to do it? MongoDB.
Answer the question
In order to leave comments, you need to log in
there is a great method .mapReduce
:
var map = function(){
if(this.name) {
emit(this.name, 1);
}
}
var reduce = function(key, values){
return Array.sum(values);
}
var res = db.collection.mapReduce(map, reduce, {out:{ inline : 1}}); // < //
db[res.result].find({value: {$gt: 1}}).sort({value: -1});
SELECT
`column_name`,
COUNT(`column_name`) AS `count`
FROM
`table`
GROUP BY
`column_name`
HAVING
`count` > 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question