mongo db 日常操作语法返回指定列,时间戳转格式化日期

74 阅读1分钟
db.getCollection('hailing_history_coordinate').aggregate([{
			$match: {
				sn: "X2020221009Y4C5J42",
				timestamp: {
					$gt: new Date("2022-12-02 10:39:10").valueOf(),
					$lt: new Date("2022-12-02 10:50:53").valueOf()
				}
			}
		}, //查询条件字符串转时间戳
		{
			$project: {
				year: {
					$add: [new Date(0), "$timestamp"]
				}, // 为时间戳别名格式化为日期
				_id: 1,
				sn: 1,
				lon: 1,
				lat: 1,
				timestamp: 1
			}
		}, // 指定查出列
		{
			$sort: {
				_id: -1
			}
		} // 排序
	])

原有数据 image.png