2015年8月11日

摘要: > sudo service mongodb start > mongo > exit #退出mongodb 覆盖索引查询 所有的查尊字段都是索引的一部分,所有的查询返回字段在同一个索引中。由于索引存在RAM中,因为索引获取数据要比扫描文档快。 > db.users.ensureIndex({g... 阅读全文
posted @ 2015-08-11 17:06 forever_elf 阅读(234) 评论(0) 推荐(0)
 
摘要: > sudo service mongodb start > mongo > mongo --shutdown #关闭MongoDB服务 查询语句条件 1.> $gt = $gte db.user.find({"age":{$gt:10,$lt:15}}) #在user中查询年龄大... 阅读全文
posted @ 2015-08-11 14:43 forever_elf 阅读(348) 评论(0) 推荐(0)
 
摘要: > sudo service mongodb start > mongo > use test #创建数据库 > show dbs # 显示所有数据库 > db.dropDatabase() #删除数据库 > db.createCollection("collectionName") #db.cr... 阅读全文
posted @ 2015-08-11 10:52 forever_elf 阅读(178) 评论(0) 推荐(0)
 
摘要: find > db.collectionName.find() #返回所有数据 > db.collectionName.find().pretty() #可以使返回数据更美观 当find()中传入多个键值对时,MongoDB就会将其作为and查询处理。语法:db.collectionName... 阅读全文
posted @ 2015-08-11 09:44 forever_elf 阅读(194) 评论(0) 推荐(0)