mongo__4.23

也支持同 mysql 一样的读取启动配置文件的方式来启动数据库,配置文件的内容如下
    [root@localhost bin]# cat /etc/mongodb.cnf
    dbpath=/data/db/
启动时加上”-f”参数,并指向配置文件即可
    [root@localhost bin]# ./mongod -f /etc/mongodb.cnf  
    Mon May 28 18:27:18 [initandlisten] MongoDB starting : pid=18481
    dbpath=/data/db/ 32-bit
    ......
    Mon May 28 18:27:18 [initandlisten] waiting for connections on port 27017
    Mon May 28 18:27:18 [websvr] web admin interface listening on port 28017


 

 

find() 来查询, 他返回一个任意结构的集合.
实现上面同样的查询, 然后通过 while 来输出


  > var cursor = db.things.find();
  > while (cursor.hasNext()) printjson(cursor.next());
  { "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "name" : "mongo" }
  { "_id" : ObjectId("4c2209fef3924d31102bd84b"), "x" : 3 }
  { "_id" : ObjectId("4c220a42f3924d31102bd856"), "x" : 4, "j" : 1 }
  { "_id" : ObjectId("4c220a42f3924d31102bd857"), "x" : 4, "j" : 2 }
  { "_id" : ObjectId("4c220a42f3924d31102bd858"), "x" : 4, "j" : 3 }
  { "_id" : ObjectId("4c220a42f3924d31102bd859"), "x" : 4, "j" : 4 }
  { "_id" : ObjectId("4c220a42f3924d31102bd85a"), "x" : 4, "j" : 5 }

posted @ 2013-04-23 16:04  jason&li  阅读(133)  评论(0编辑  收藏  举报