#!/usr/bin/python
#-*-Coding:utf-8-*-
Import Sys
Import OS
Import JSON
From Pymongo import mongoclient
Import datetime
#获取系统当前日期
Today = Datetime.datetime.now ()
#取指定前几天的日期
Lastday = Today + Datetime.timedelta (days=-4)
#连接mongod的方式采用url
Client = mongoclient (' Mongodb://user:[email protected]:27017/kyelog ')
#指定mongdb的数据库
db = client[' Kyelog ')
#指定数据库的集合名称
Collection = Db[' Autologisticsphlog ']
#mongo的日期格式new Date,python Call cannot be judged, it needs to be converted to datetime time
#for I in Collection.find ({"Logdt": {' $lt ': New Date ("2018-02-09t01:16:33.303z")}}):
#查询指定日期之前的数据find ({"Logdt": {' $lt ':d atetime.datetime (2018,2,8,12,55,59)}})
#for I in Collection.find ({"Logdt": {' $lt ':d atetime.datetime (lastday.year,lastday.month,lastday.day,7,53,11)}}):
# Print (i)
#删除指定日期之前的数据collection. Remove ({"Logdt": {' $lt ':d atetime.datetime (2018,2,8)}})
Collection.remove ({"Logdt": {' $lt ':d atetime.datetime (lastday.year,lastday.month,lastday.day,5,58,58)}})
Python action MONGO script