mongoDB操作命令

更新列名
db.Youzy_Stores.update({}, {$rename : {"StoreId" : "MetaId"}}, false, true)

查询长度
db.getCollection("Youzy_Stores_Navigations").find({$where:'this.StoreId.length>2'},{Name:0})

查询总条数
db.getCollection("Youzy_Stores_BusinessLogs").find({}).count()

排序 1 升序 -1降序
db.getCollection("Youzy_Stores_BusinessLogs").find().sort({"CreationTime":1})

更改字段类型 http://note.youzy.cn/notes/content/8903
db.Youzy_Stores_Experts.find({'PicId' : { $type : 16 }}).forEach(function(x) {x.PicId = String(x.PicId);db.Youzy_Stores_Experts.save(x); })

添加一个字段. 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('Youzy_Orders_Scores').update({},{$rename:{"OId":'MetaId'}},false,true)
添加索引
db.test.ensureIndex({"username":1})
--条件修改
db.getCollection('Youzy_Stores_Navigations').update(
// query
{
"MenuKey" : 28
},

// update
{
$set:{"Url":"/tzy/choosebatch?type=3"}
},
false,
true
);

posted @ 2024-03-03 11:59  W(王甜甜)  阅读(30)  评论(0编辑  收藏  举报