MongoDB MapReduce Combat <2>

Source: Internet
Author: User
Tags mongodb
Millions of of the data in the database, processing may be slow, so it is simple to build a smaller structure of similar tables, test data
/* 0 */
{
  "_id": ObjectId ("54fe73e36e26d21dc4391bdb"),
  "Create_date": Isodate ("2014-07-26t13:57:18z"),
  "Rfid_no": "010101000120140322000173"
}

/* 1 */
{
  "_id": ObjectId ("54FE74076E26D21DC4391BDC"),
  "Create_date": Isodate ("2014-07-24t11:57:18z"),
  "Rfid_no": "010101000120140322000173"
}

/* 2 */
{
  "_id": ObjectId ("54FE74136E26D21DC4391BDD"),
  "Create_date": Isodate ("2014-07-27t09:27:18z "),
  " Rfid_no ":" 010101000120140322000173 "
}

/* 3
*
  /{" _id ": ObjectId (" 54fe742a6e26d21dc4391bde "),
  " Create_date ": Isodate (" 2014-07-26t13:57:18z "),
  " Rfid_no ":" 010101000120140322000883 "
}
It is important to note that the join statement for the time type is:
Db.test.save ({rfid_no: ' 1 ', create_date:new DATE (' 6/26/2014 13:57:18 ')});
Writing a map
function Map () {
	//Remove the same time record as RFID in the log record
	emit (this
		. Rfid_no, this
		. Create_date
	); 
}
Write reduce
function Reduce (key, values) {
	//combine the same RFID payback time into a record of
	var ret = {rfid:key, times:[{}]};
	for (var i = 0;i < values.length;i++) {
		ret.times[i] = values[i];
	}
	return ret;
}
Configure in & Out
To run and produce the result:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.