ITeye博客

mongodb基础

catdoc · 2014-11-07 21:34 · redis · 移动开发 · Markdown

debian下安装 mongodb

wget http://downloads.mongodb.org/linux/mongodb-linux-i686-2.6.4.tgz tar -zxvf http://downloads.mongodb.org/linux/mongodb-linux-i686-2.6.4.tgz

mkdir -p /data/db ./mongod --dbpath /data/db 启动mongod服务器

By default, mongo looks for a database server listening on port 27017 localhost. the --port and --host options.

./mongo --port 27017 --host 192.168.228.174

db 查看当前使用哪个数据库 show dbs 查看所有数据库 use mydb

帮助命令: help

MongoDB will create a collection implicitly upon its first use. You do not need to create a collection before inserting data. Furthermore, because MongoDB uses dynamic schemas, you also need not specify the structure of your documents before inserting them into the collection.

use skydb 此时 并未创建skydb,只有第一次插入数据才会真正创建skydb j = { name : "sky" , age : 27} k = { x : 3 } db.myData.insert(j) myData是skydb数据库的一个collection db.myData.insert(k) insert一次表示 一条记录

show collections 显示当前数据库的 collection集

db.myData.find() 查看 myData collection的内容

find()返回的是一个游标,通过迭代 var c = db.testData.find() while ( c.hasNext() ) printjson( c.next() ) 或者 printjson( c )

db.myData.find( { name : "sky}) 作为条件查找

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。