pymongo是Python对MongoDB的操作库。但是由于python没有IOSDate类型,所以对Mongo的时间类型是个很麻烦的操作。整理一个把python能识别的date类型转化为IOSDate类型

脚本如下:
#!/usr/bin/python
import pymongo
from dateutil import parser
dateStr = '2018-06-12T00:00:00.000Z'
myDatetime = parser.parse(dateStr)
client = pymongo.MongoClient(host="192.168.2.14",port=29019)
db = client.dbs
db.authenticate()
db.ceshi.insert({'date': myDatetime})

到MongoDB里查看数据:

testin.dbs>db.ceshi.find()
  { "_id" : ObjectId("5b3054fa29e93634dcc21645"), "date" : ISODate("2018-06-12T00:00:00Z") }

已经插入ISODate格式时间。

pymongo查询数据实操:

import pymongo,datetime
from dateutil import parser
def findmongo():
time1 = datetime.datetime.now() dateStr1 = '2019-01-21T00:00:00Z'
dateStr2 = '2019-01-23T00:00:00Z'
myDatetime1 = parser.parse(dateStr1)
myDatetime2 = parser.parse(dateStr2) client = pymongo.MongoClient(host="0.0.0.0", port=3717)
db = client.mongolilly
db.authenticate("root","admin") a = db.current_temp.find({"order_id":"465","scan_time":{ "$gte": myDatetime1, "$lte":myDatetime2}})
time2 = datetime.datetime.now()
time3 = time2 - time1
print "time3------->select_time :%s" % time3 list = []
for i in a :
data = {
"number": i["number"],
"temperature": i["temperature"],
"scan_time": i["scan_time"],
"scan_location": i["scan_location"],
"battery": i["battery"],
"rssi": i["rssi"],
"mac": i["mac"],
"order_id": i["order_id"]
# "id": str(one_info.id)
}
list.append(data) time4 = datetime.datetime.now()
time5 = time4-time1
print "time5------>all_time:",time5

解决pymongo里操作IOSDate类型的问题的更多相关文章

  1. [oracle] Oracle存储过程里操作BLOB的字节数据的办法,例如写入32位整数

    作者: zyl910 一.缘由 BLOB是指二进制大对象,也就是英文Binary Large Object的缩写. 在很多时候,我们是通过其他编程语言(如Java)访问BLOB的字节数据,进行字节级的 ...

  2. 基于PLSQL的数据库备份方法及如何解决导出clob和blob类型数据报错的问题

    基于PL/SQL的数据库备份方法 PL/SQL Developer是Oracle 数据库中用于导入或导出数据库的主要工具,本文主要介绍了利用PL/SQL Developer导入和导出数据库的过程,并对 ...

  3. 解剖SQLSERVER 第五篇 OrcaMDF里读取Bits类型数据(译)

    解剖SQLSERVER 第五篇  OrcaMDF里读取Bits类型数据(译) http://improve.dk/reading-bits-in-orcamdf/ Bits类型的存储跟SQLSERVE ...

  4. 转:JAVA里面的int类型 和Integer类型,有什么不一样

    JAVA里面的int类型 和Integer类型,有什么不一样 原文链接:http://blog.csdn.net/wuxinliulei/article/details/11099565 java.l ...

  5. flask 在视图函数里操作数据库

    在视图函数里操作数据库 在视图函数里操作数据的方式和在python shell中的联系基本相同,只不过需要一些额外的工作.比如把查询结果作为参数 传入模板渲染出来,或是获取表单的字段值作为提交到数据库 ...

  6. JAVA里面的int类型 和Integer类型,有什么不一样

    JAVA里面的int类型 和Integer类型,有什么不一样 原创 2013年09月04日 23:15:11 标签: java / 2120 编辑 删除 JAVA里面的int类型 和Integer类型 ...

  7. Win64 驱动内核编程-7.内核里操作进程

    在内核里操作进程 在内核里操作进程,相信是很多对 WINDOWS 内核编程感兴趣的朋友第一个学习的知识点.但在这里,我要让大家失望了,在内核里操作进程没什么特别的,就标准方法而言,还是调用那几个和进程 ...

  8. Win64 驱动内核编程-5.内核里操作文件

    内核里操作文件 RING0 操作文件和 RING3 操作文件在流程上没什么大的区别,也是"获得文件句柄->读/写/删/改->关闭文件句柄"的模式.当然了,只能用内核 A ...

  9. winform里操作打开在panel里的form窗体,子窗体操作同级子窗体或者父窗体的方法

    最近开始了一个winform项目,原先一直都是web项目.遇到个问题,就是在框架内,左侧和中间的main都是用panel来实现的form,就是把form窗体打开到panel里,实现左侧是导航,中间是操 ...

随机推荐

  1. 使用OPCNetAPI连接OPCServer

    OPCServer KepServer; OPCGroup KepGroup; bool opc_connected; string remoteServerName = "KEPware. ...

  2. 张量系列(tensor02)

    张量的两种运算 1. 张量的乘(Tensor product) tensorproduct() 2. 张量的缩并 tensorcontraction() The matrix trace is equ ...

  3. API使用

    至于什么是API我想不用累述了,百科上面有,其实就是别人写好了一大堆功能性的代码,然后你可以拿来用.一般的二次开发都是使用api来开发,包括现在的高级程序设计,很少自己写基本代码了,像.netFram ...

  4. 最基本的区块链hello world(python3实现)

    源自 用不到 50 行的 Python 代码构建最小的区块链 (英文原文:Let’s Build the Tiniest Blockchain ) ,但是文中的代码是基于python2的,python ...

  5. app v2界面

             相比v1要流畅了很多

  6. Recover database using backup controlfile until cancel

    http://searchoracle.techtarget.com/answer/Recover-database-using-backup-controlfile-until-cancel Wha ...

  7. 3728 联合权值[NOIP 2014 Day1 T2]

    来源:NOIP2014 Day1 T2 OJ链接: http://codevs.cn/problem/3728/ https://www.luogu.org/problemnew/show/P1351 ...

  8. (原)Show, Attend and Translate: Unsupervised Image Translation with Self-Regularization and Attention

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9333844.html 论文网址:https://arxiv.org/abs/1806.06195 在 ...

  9. [转]抛弃jQuery,使用原生JavaScript

    原文链接 Document Ready 事件 在jQuery中,document.ready可以让代码在整个文档加载完毕之后执行: $(document).ready(function() { // ...

  10. CentOS 7.4安装Nginx 1.14.0

    一.安装所需环境   1.gcc 安装         yum install gcc-c++