【部分答案】头歌/educoder/数据库原理与应用/NoSQL

db.educoder.insertMany([{_id:1,course:'Python表达式问题求解实训',author:'李暾',tags:['Python基础','求解'],learning_num:1882},{_id:2,course:'Java语言之基本语法',author:'余跃',tags:['Java基础','语法'],learning_num:814},{_id:3,course:'Python面向对象编程实训',author:'李暾',tags:['Python基础','面向对象'],learning_num:143},{_id:4,course:'Android综合实训之物联网移动应用开发(1)',author:'prophet5',tags:['Android','物联网','移动开发'],learning_num:207}]);

db.student.insertMany([{_id:1,name:'王小明',age:15,score:90},{_id:2,name:'周晓晓',age:18,score:86},{_id:3,name:'王敏',age:20,score:96},{_id:4,name:'李晓亮',age:15,score:74},{_id:5,name:'张青青',age:21,score:88}]);

db.article.insertMany([{_id:1,title:'提升程序员工作效率的6个工具利器',tags:["Alfred","幕布"],follwers:543},{_id:2,title:'我是如何从零开始学习前端的	',tags:["HTML","Html5","CSS"],follwers:1570},{_id:3,title:'20个非常有用的JAVA程序片段	',tags:["Java","编程"],follwers:1920}]);

db.people.insertMany([{_id:1,name:'A',personloc:{type:'Point',coordinates:[116.403981,39.914935]}},{_id:2,name:'B',personloc:{type:'Point',coordinates:[116.433733,39.909511]}},{_id:3,name:'C',personloc:{type:'Point',coordinates:[116.488781,39.949901]}},{_id:4,name:'D',personloc:{type:'Point',coordinates:[116.342609,39.948021]}},{_id:5,name:'E',personloc:{type:'Point',coordinates:[116.328236,39.901098]}},{_id:6,name:'F',personloc:{type:'Point',coordinates:[116.385728,39.871645]}}]);

db.test.find({'age':20,'sex':'男'}).sort({_id:1});
db.test.find({\$or:[{'age':20},{'sex':'男'}]}).sort({_id:1});
db.test.find({name:/^韩.*/}).sort({_id:1});
db.test.find({\$and:[{age:{\$gte:19}},{age:{\$lt:22}}]}).sort({_id:1});
db.test.find({\$or:[{age:{\$lt:19}},{age:{\$gt:21}}]}).sort({_id:1});
db.test.find({name:{\$not:/^韩.*/}}).sort({_id:1});
db.test.find({name:{\$not:/^韩.*/}}).count();
db.test.find({\$and:[{age:{\$gte:19}},{age:{\$lt:22}}]}).count();


mkdir -p /data/test2/shard1/db
mkdir -p /logs/test2/shard1/log
mkdir -p /data/test2/shard2/db
mkdir -p /logs/test2/shard2/log
mkdir -p /data/test2/shard3/db
mkdir -p /logs/test2/shard3/log
mkdir -p /data/test2/config/db
mkdir -p /logs/test2/config/log
mkdir -p /logs/test2/mongs/log
mkdir -p /etc/test2
 
vim /etc/test2/mongod1.conf
 
dbpath=/data/test2/shard1/db
logpath=/logs/test2/shard1/log/mongodb.log
port=21001
shardsvr=true
fork=true
 
vim /etc/test2/mongod2.conf
 
dbpath=/data/test2/shard2/db
logpath=/logs/test2/shard2/log/mongodb.log
port=21002
shardsvr=true
fork=true
 
vim /etc/test2/mongod3.conf
 
dbpath=/data/test2/shard3/db
logpath=/logs/test2/shard3/log/mongodb.log
port=21003
shardsvr=true
fork=true
 
mongod -f /etc/test2/mongod1.conf
mongod -f /etc/test2/mongod2.conf
mongod -f /etc/test2/mongod3.conf
 
mongod --dbpath /data/test2/config/db --logpath /logs/test2/config/log/mongodb.log --port 21004 --configsvr --replSet cs --fork
 
mongo localhost:21004
 
use admin;
cfg = {
  _id:'cs',
  configsvr:true,
  members:[
      {_id:0,host:'localhost:21004'}
   ]
};
rs.initiate(cfg);
 
exit
 
mongos --configdb cs/localhost:21004 --logpath /logs/test2/mongs/log/mongodb.log --port 21005 --fork
 
 
mongo localhost:21005
 
sh.addShard('localhost:21001');
sh.addShard('localhost:21002');
sh.addShard('localhost:21003');
 
 
sh.status();
 
 
mkdir /opt/mongodb
mkdir /opt/mongodb_1
mkdir /opt/mongodb_2
mkdir /opt/collection_1
mkdir /opt/collection_2
mongoimport -d test1 -c person --type json --file /home/example/person.json
mongoimport -d test2 -c student --type csv --headerline --ignoreBlanks --file /home/example/student.csv


 
mongodump -h 127.0.0.1:27017 --authenticationDatabase admin  -o /opt/mongodb
mongodump -h 127.0.0.1:27017 --authenticationDatabase admin  -d test1 -o /opt/mongodb_1
mongodump -h 127.0.0.1:27017 --authenticationDatabase admin  -d test1 -c person -o /opt/collection_1
mongodump -h 127.0.0.1:27017 --authenticationDatabase admin  -d test2 -c student -o /opt/collection_2 --gzip
mongodump -h 127.0.0.1:27017 --authenticationDatabase admin  -d test2 -o /opt/mongodb_2 --gzip



mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin --drop  /opt/mongodb
mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin -d mytest1 /opt/mongodb_1/test1
mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin -d mytest2 -c person /opt/collection_1/test1/person.bson
mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin -d mytest3 -c student --gzip --drop /opt/collection_2/test2/student.bson.gz
mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin -d mytest4  --gzip --drop /opt/mongodb_2/test2/student.bson.gz

 

MongoDB 复制集 & 分片

MongoDB 文档的高级查询操作

MongoDB 实验——数据备份和恢复

MongoDB 实验——数据库优化

MongoDB 实验——java 和 MongoDB

MongoDB 之聚合函数查询统计

MongoDB 之滴滴、摩拜都在用的索引

MongoDB数据库安全

MongoDB 数据库基本操作

初识 MongoDB

头歌实验,不知道是哪个了,本地notepad++写的内容,删了总比发了好,保证都是能满分的

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值