mongoose

来源:互联网 发布:如何注销淘宝账号 编辑:程序博客网 时间:2024/06/05 03:45
mongo   使用数据库
mongod  开机
mongoimport  导入数据
mongod --dbpath d:\xxxx




列出所有数据库:
show dbs 


use 数据库名字


查看当前所在数据库
db
插入数据:db.stu.insert({});
查找数据db.stu.find();


删除数据库,删除当前所在的数据库
    db.dropDatabase();
用来从数据库中删除一个集合。
    db.collection.drop() 


mongoimport --db test --collection restaurants --drop --file primer-dataset.json
-db test  想往哪个数据库里面导入
--collection restaurants  想往哪个集合中导入
--drop 把集合清空
--file primer-dataset.json  哪个文件


大于条件:
db.student.find({"score.yuwen":{$gt:50}});


寻找所有年龄是9岁,或者11岁的学生 
db.student.find({$or:[{"age":9},{"age":11}]});


查找完毕之后,打点调用sort,表示升降排序。1升-1降
1db.restaurants.find().sort( { "borough": 1, "address.zipcode": 1 } )




查找数学成绩是70,把年龄更改为33岁:
db.student.update({"score.shuxue":70},{$set:{"age":33}});
更改所有匹配项目:"
db.student.update({"sex":"男"},{$set:{"age":33}},{multi: true});


删除数据
db.restaurants.remove( { "borough": "Manhattan" } )
db.restaurants.remove( { "borough": "Queens" }, { justOne: true } )




加入,第一页是page=0。每页10条,所以当前页的查询语句
1db.student.find({}).limit(10).skip(page*10)
数据总数怎么得到
shell中

db.student.stats().count;


原创粉丝点击