MongoDB Shell 命令

更新列名

db.Stores.update({}, {$rename : {"StoreId" : "MetaId"}}, false, true)

查询长度

db.getCollection("Stores_Navigations").find({$where:'this.StoreId.length>2'},{Name:0})

查询总条数

db.getCollection("Stores_BusinessLogs").find({}).count()

区间查询

db.getCollection("Cards").find({'StoreId':1139,'CardNo':{'$gte':'90225001','$lte':'90295000'}})

排序 1升序 -1降序

db.getCollection("Stores_BusinessLogs").find().sort({"CreationTime":1})

更改字段类型

// 16代表int db.Stores_Experts.find({'PicId' : { $type : 16 }}).forEach(function(x) {x.PicId = String(x.PicId);db.Stores_Experts.save(x); })

字段类型表

类型 对应数字 别名
Double 1 double
String 2 string
Object 3 object
Array 4 array
Binary data 5 binData
Undefined 6 undefined
ObjectId 7 objectId
Boolean 8 “bool”
Date 9 “date”
Null 10 “null”
Regular Expression 11 “regex”
DBPointer 12 “dbPointer”
JavaScript 13 “javascript”
Symbol 14 “symbol”
JavaScript(with scope) 15 “javascriptWithScope”
32-bit integer 16 “int”
Timestamp 17 “timestamp”
64-bit integer 18 “long”
Min key -1 “minKey”
Max key 127 “maxKey”
- - -

添加一个字段. table 代表表名 , 添加字段 content,字符串类型

db.table.update({}, {$set: {content:""}}, {multi: true})

删除一个字段

db.table.update({},{$unset:{content:""}},false, true)

清空数据

db.table.remove({})

查询指定列

db.news.find( {}, { id: 1, title: 1 } )

修改列表

db.getCollection('Orders_Scores').update({},{$rename:{"OId":'MetaId'}},false,true)

添加索引

db.test.createIndex({"username":1}) db.Users_MobileAuthCodes.createIndex({"Code":1,"Mobile":1,"ExpiresTime":1},{"name":"MobileAuthCodes_Validate"})

group分组

db.getCollection("Users_GaoKaoScores").aggregate([{$match:{"IsDeleted":false}},{$group : {_id : "$UserId", count : {$sum : 1}}},{$sort:{"count":-1}}])

按条件修改update

db.getCollection('Stores_Navigations').update( // query { "MenuKey" : 28 }, // update { $set:{"Url":"/tzy/choosebatch?type=3"} }, false, true );

__EOF__

本文作者阿星Plus
本文链接https://www.cnblogs.com/meowv/p/11310444.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   阿星Plus  阅读(286)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示