NoSQL Manager for MongoDB:https://www.mongodbmanager.com/download mongodbmanagerfree_inst
mongo日期类型 http://blog.csdn.net/shiyaru1314/article/details/53465232 http://www.cnblogs.com/yuechaotian/archive/2013/02/02/2889824.html
利用JAVA API 从Mongodb中查询Date类型的数据: http://www.cnblogs.com/zhengchunhao/p/5695190.html
long date = 1468758769761L;
Date isoDate = new Date(date);
FindIterable<Document> findIterable = collection.find(gt("upLineDate", isoDate)).batchSize(1000);
在Mongodb中时间的存储格式为ISODate,如下所示,ISODate时间表示格林尼治时间,而我们通常需要看的时间是我们的东八区时间
"offLineDate" : ISODate("2016-07-18T00:20:59.248Z"),
"upLineDate" : ISODate("2016-07-18T00:20:41.529Z"),
在java mongoDB driver获取的时候,API内部其实已经作了转换,从ISODate---》Date, 具体可参考如下这篇文章
http://blog.csdn.net/doctor_who2004/article/details/50449561
while (mongoCursor.hasNext())
{
Document doc = mongoCursor.next();
Date tempDate = doc.getDate("upLineDate");
System.out.println(df.format(tempDate)); //2016-07-18 12:01:22 本地时间
}
show dbs
use db;
show collections
db.collection01.insert({ "orderId":2, "createTime":Date(), "user":{ "userName":"lisi" } })
把原来的 createTime:Date() 修改为 createTime:new Date() ISODate类型
db.collection01.find().forEach(function(item) { print(item.createTime); item.createTime = new Date(); db.collection01.save(item); })
更新
var ones = db.Photo.find({'owner.$id':ObjectId("5344f0dab7c58e8e098b4567")}) db.Photo.find({'owner.$id':ObjectId("5344f0dab7c58e8e098b4567")}).forEach(function(o){o.owner=null;db.Photo.save(o)});
db.User.find().forEach( function(item){ db.User.update({"_id":item._id},{"$set":{"LastUpdate":item.CreateAt}},false,true) } )
db.collection01.update({"user":{"userName":"zhangsan"}} ,{"orderId":3} ); //左边为选择器, 更新后 其他没设置的属性丢失了 createTime,user 都没了,只剩下当前设置的 orderId
db.collection01.update({"user":{"userName":"zhangsan"} }, {"$set": {"orderId":5}} )//通过$set只更新设定的字段,其余的不变
db.collection01.update({"user":{"userName":"zhangsan"}} ,{"orderId":3,"createTime":new Date(),"user":{"userName":"zhangsan" }} );
根据日期范围查询 db.collection01.find({ "createTime":{"$lt":new Date("2017/07/08")}}) //插入时 日期使用 new Date()方式
db.collection01.find().sort({"orderId":-1}).skip(50).limit(10);//倒排
db.collection01.find().sort({"orderId":1}).skip(50).limit(10);//asc
skip的效率比较低 ,

浙公网安备 33010602011771号