mongodb常用命令

集群搭建https://blog.csdn.net/kevinmcy/article/details/82712074

1.创建空文件注意点
将mkdir替换为touch,仅限创建空的文件
touch -p /home/mongodb/log/config.log
touch -p /home/mongodb/log/mongos.log
touch -p /home/mongodb/log/shard1.log
touch -p /home/mongodb/log/shard2.log
touch -p /home/mongodb/log/shard3.log

rs.initiate({_id:“configs”,members:[{_id:0,host:“192.168.23.132:27018”},{_id:1,host:“192.168.23.133:27018”}, {_id:2,host:“192.168.23.134:27018”}]})

rs.initiate({_id:“shard1”,members:[{_id:0,host:“192.168.23.132:27001”},{_id:1,host:“192.168.23.133:27001”},{_id:2,host:“192.168.23.134:27001”}]})

sh.addShard(“shard1/192.168.23.132:27001,192.168.23.133:27001,192.168.23.134:27001”)
sh.addShard(“shard2/192.168.23.132:27002,192.168.23.133:27002,192.168.23.134:27002”)
sh.addShard(“shard3/192.168.23.132:27003,192.168.23.133:27003,192.168.23.134:27003”)

  1. db.status()
    db.user.getIndexes()
    db.user.findOne()
    db.user.stats()

db.qikegu.insert([
{
title: ‘MongoDB 入门’,
description: ‘MongoDB是一个以文档为中心的NOSQL数据库’,
by: ‘qikegu.com’,
url: ‘https://www.qikegu.com’,
tags: [‘mongodb’, ‘database’, ‘NoSQL’],
likes: 88
},

{
title: ‘MongoDB 优势’,
description: “MongoDB相对于RDBMS的优势”,
by: ‘qikegu.com’,
url: ‘https://www.qikegu.com’,
tags: [‘mongodb’, ‘database’, ‘NoSQL’],
likes: 89,
comments: [
{
user:‘user1’,
message: ‘My first comment’,
dateCreated: new Date(2018,11,10,2,35),
like: 0
}
]
}
])

3.按时间查询

db.xxx.find({“ct”:{KaTeX parse error: Expected 'EOF', got '}' at position 24: …Date(2016,11,1)}̲}) mongoDB对时间的处…gt":ISODate(“2017-04-20T01:16:33.303Z”)}}) // 大于某个时间

db.getCollection(‘CustomerBehaviorLog_0407’).
find({
CreateTime: {
$gte: ISODate(“2020-03-31T16:00:00.000Z”),
KaTeX parse error: Expected 'EOF', got '}' at position 45: …:00.000Z") }̲, "BehaviorType…in":[1,2]}
}).count();

4.按条件导出数据
mongoexport -u user -p pwd! -d dbName -c users -q ‘{age:20}’ -o /data/date.json
mongoexport -u user -p pwd! -d dbName -c users --type=csv -f _id,name,age -o /data/date.csv
导入数据
mongoimport -u user -p pwd -d dbName -c users --file /data/date.json
mongoimport -u user -p pwd -d dbName -c users --type=csv --headerline --file /data/date.csv

mongoimport -u admin -p admin -d admin -c customer_0303 --file customer_0303.json

mongoexport -h 182.254.150.218:27017 -u leyou -p leyou -d leyou -c CustomerBehaviorLog_0407 -q ‘{“CreateTime”:{ g t e : I S O D a t e ( " 2020 − 03 − 30 T 16 : 00 : 00.000 Z " ) , gte: ISODate("2020-03-30T16:00:00.000Z"), gte:ISODate("20200330T16:00:00.000Z"),lt: ISODate(“2020-03-31T16:00:00.000Z”)}}’ -o customer_0330.json
mongoexport -u admin -p admin -d admin -c CustomerBehaviorLog_1024 -q ‘{“CreateTime”:{“ g t e " : I S O D a t e ( " 2020 − 03 − 0306 : 22 : 56.580 Z " ) , " gte":ISODate("2020-03-03 06:22:56.580Z")," gte":ISODate("2020030306:22:56.580Z"),"lte”:ISODate(“2020-03-04 06:22:56.580Z”)}}’ -o customer_0303.json
mongoexport -u admin -p admin -d admin -c CustomerBehaviorLog_1024 -q ‘{"_id":{“ g t e " : O b j e c t I d ( " 5 e 5 d f 7 c 071 a b 8 a 1 c e 48 e e a e 8 " ) , " gte":ObjectId("5e5df7c071ab8a1ce48eeae8")," gte":ObjectId("5e5df7c071ab8a1ce48eeae8"),"lt”:ObjectId(“5e5f48f82ddbfa05f0ee3d9d”)}}’ -o customer_0303.json

5.建库、建表
use test2
db.createCollection(‘customer_0303’);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值