
DB
刘看水
这个作者很懒,什么都没留下…
展开
-
mongo 替换某个字段中的某个特定字符
数据库 member 表字段格式举例:{ "_id" : ObjectId("xxxxxx"), ... "socials" : [ { "channel" : "wechat-channelId1", "openId" : "wechat是是openId1", }, ...原创 2019-12-12 19:39:56 · 542 阅读 · 0 评论 -
MongoDB 索引管理
索引的创建创建索引 createIndex() 方法3.0.0 版本之前使用 ensureIndex() 方法创建索引,之后的版本用 createIndex(),ensureIndex() 还能用,但只是 createIndex() 的别名db.collection.createIndex(keys, options)db.collection.ensureIndex()...原创 2019-09-23 14:30:11 · 128 阅读 · 0 评论 -
Mongo 查询不区分大小写
db.COLLECTION.find({"FIELD": {'$regex': 'VALUE', '$options': 'i'}});原创 2019-09-19 10:52:02 · 1871 阅读 · 0 评论 -
mongo obj 转 str
// 转化 obj to str$project: { _id: { $toString: "$_id" }}原创 2019-08-16 16:56:07 · 209 阅读 · 0 评论 -
postgresql 复制表
1.INSERT INTO FROM 语句insert into tablebackup select * from table;insert into tablebackup select field1,field2,field3 from table where ...;前提:tablebackup 必须存在2. SELECT INTO FROM 语句select * ...原创 2019-08-12 15:41:00 · 5949 阅读 · 0 评论 -
mongodb 查询数据库状态
db.stats();db.collectionName.stats();查询数据库各表状态var collectionNames = db.getCollectionNames();collectionNames.forEach(function(collection) { var stats = db.getCollection(collection).stats(...原创 2019-06-05 09:35:50 · 1979 阅读 · 0 评论 -
mongo 知识
为防止更新数据导致 cursor 乱掉,可以加命令 xxx.snapshot().xxx原创 2019-06-13 16:42:31 · 159 阅读 · 0 评论 -
mongo shell 输出 _id 的方法
输出为 ObjectIddb.member.find().noCursorTimeout().forEach(function(item) { print(item._id.toString());});ObjectId("5bd2e2896527950049805f99")ObjectId("5bd2e9846527950049805f9c")ObjectId("5b...原创 2019-05-29 15:21:47 · 1168 阅读 · 0 评论 -
mongo 索引状态
db.member.aggregate([ { $indexStats: {} } ])原创 2019-06-12 17:00:58 · 271 阅读 · 0 评论 -
mongo aggregate 时区问题
MongoDB 中的时间 mongoDate 是按照标准时间 UTC +0:00 来存储的,而中国时区是 +8.00。 由于时差的原因在使用聚合函数$dateToString 时发现统计不准确的问题。如下:db.event.aggregate([ {$project: { "occurredAt": 1, "occurredAtStr": { ...原创 2019-05-30 15:47:55 · 1655 阅读 · 1 评论 -
mongo find
db.member.find()/* 1 */{ "_id" : ObjectId("5cef7216c743b45966256aed"), "name" : "张三", "gender" : "male", "phone" : "13012340001", "isDeleted" : false}/* 2 */{ "_id" : O...原创 2019-05-30 14:32:49 · 265 阅读 · 0 评论 -
mongo update
mongoupdateMany/* 1 */{ "_id" : ObjectId("5cef7216c743b45966256aed"), "name" : "张三", "gender" : "male", "phone" : "13012340001", "isDeleted" : false}/* 2 */{ "_id" : O...原创 2019-05-30 14:17:09 · 1014 阅读 · 0 评论 -
MySQL 时间和日期
MySQL 的时间和日期类型数据类型 字节数 数据格式 year 1 YYYY date 4 YYYY-MM-DD time 3 HH:MM:SS datetime 8 YYYY-MM-DD HH:MM:SS timestamp 4 YYYY-MM-DD HH:MM:SS ...原创 2019-05-16 15:34:24 · 179 阅读 · 0 评论 -
mysql 查询
desc(查询表结构)desc dbname.tablename;distinctselect count(distinct name)from dbname.tablename;查询 timestamp 格式的字段// 传统方法效率较低SELECT * FROM tablename createdat < '2019-01-01 00:00:00' ORDER...原创 2019-05-16 10:10:42 · 129 阅读 · 0 评论 -
mongo 默认查询顺序
如果 mongo 查询没有指定 sort 排序,那么 find() 的结果集的默认顺序为插入的顺序MongoDB 自然排序natural order该排序下数据库参照文档在磁盘上的存储顺序。这是默认的排序顺序。...原创 2019-05-20 14:21:16 · 5226 阅读 · 1 评论 -
Mongo distinct 查询
1. 使用 distinct 语句db.member.distinct("phone");此语句会列出 member 表所有数据去重后的 phone 的值,如下所示:/* 1 */[ "13011111111", "", "13012341234", "13922222222", "15056785678", "1509999999...原创 2019-05-09 08:34:16 · 3605 阅读 · 0 评论