MongoDB time stamp-based derivative operation

Source: Internet
Author: User
Tags auth mongodb mongodb collection

There is a need to work, to assist in extracting a data system cashloandb

MongoDB Collection involved: Cardbill (time period 6.1-8.28), Cardreport (time period 2.1-8.28)
If you do not support time-based extraction, you can extract full-volume data.
To enter the database using the MONGO client command:
Jsfkrs0:primary> Show DBS;
2018-09-04t17:35:57.692+0800 E QUERY [thread1] error:listdatabases failed:{
"OK": 0,
"ErrMsg": "Not authorized in Admin to execute command {listdatabases:1.0}",
"Code": 13,
"codename": "Unauthorized"
}:br/>[email protected]/mongo/shell/utils.js:25:13
[Email protected]/mongo/shell/mongo.js:62:1br/>[email protected]/mongo/shell/utils.js:769:19
[Email protected]/mongo/shell/utils.js:659:15br/>@ (SHELLHELP2): 1:1
jsfkrs0:primary> Use admin
Switched to DB admin
Jsfkrs0:primary> Db.auth (' mangoadmin ', ' password ')</span></span>
1
Jsfkrs0:primary> Show DBS;
Admin 0.000GB
Cashloandb 96.287GB
Fuf_mgdb 0.765GB
Local 1.280GB

Switch to the DB we want to manipulate
Jsfkrs0:primary> Use Cashloandb
Switched to DB cashloandb

Take a look at the full amount of data for these two sets.
Jsfkrs0:primary> Db.cardBill.count ();
247126
Jsfkrs0:primary> Db.cardReport.count ();
249128

Let's see if there's time in this table. We take a piece of data to see, if there is, we can be based on this timestamp to export work;
Jsfkrs0:primary> Db.cardBill.findOne ();
{
"_id": ObjectId ("59e180110cxxxxxx"),
"Timestamp": Numberlong ("1507950609625"),
"TaskId": "Xxxxxx-b08d-11e7-bf17-xxxxx",
"Bill": "[{\" balance\ ": 47000.00,\" deposits\ ": [],\" Bills\ ": [{\" installments\ ": [],\" bill_id\ ": \" D81f1e60-a02d-11e7-a63a-00163e0dfac7\ ", \" bill_type\ ": \" done\ ", \" bank_name\ ": \" Citic bank \ ", \" bill_month\ ": \" 2017-04\ ", \" bill_date\ ": \" 2017-04-14\ ", \" Payment_due

This timestamp has 13 bits, accurate to milliseconds, we need to convert to UNIX timestamp when exporting, and also accurate to milliseconds.
Http://tool.chinaz.com/Tools/unixtime.aspx

The normal conversion comes only to the second bit, only 10 bits. Can be directly after the conversion of the UNIX timestamp 000, or the conversion of the time directly to the millisecond, down we can use the MANGODB Export tool to export;
mongoexport-d cashloandb-c cardbill-uadmin-ppassword--authenticationdatabase "admin"-Q ' {"timestamp": {$gte: Numberlong ("1517414400000"), $lte: Numberlong ("1535472000000")}} '-O Cardbill.json

MongoDB time stamp-based derivative operation

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.