4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MongoDB覚書

Last updated at Posted at 2015-06-24

前回のインストールからの続き。
#####REST Interfaceを有効にする

echo rest = true >> /etc/mongodb.conf
/etc/init.d/mongodb restart

#####データベース作成

mongo
MongoDB shell version: 2.1.1
connecting to: test
> use rasp
switched to db rasp
> db.info.insert({"name":"debian","path":"/path/to/sample"})
> db.info.find();
{ "_id" : ObjectId("558ade97e3e39a6523b43fc6"), "name" : "debian", "path" : "/path/to/sample" }

#####REST経由で追加・参照してみる

curl -d '{ "name" : "redhat", "path" : "/path/to/sample/redhat"}' 'http://localhost:28017/rasp/info/'
{ "ok" : true }
curl 'http://localhost:28017/rasp/info/'         {
  "offset" : 0,
  "rows": [
    { "_id" : { "$oid" : "558ade97e3e39a6523b43fc6" }, "name" : "debian", "path" : "/path/to/sample" } ,
    { "_id" : { "$oid" : "558ae0499ae859637fa175d5" }, "name" : "redhat", "path" : "/path/to/sample/redhat" }
  ],

  "total_rows" : 2 ,
  "query" : {} ,
  "millis" : 0
}

細かいが、最後の"/"を忘れると取得に失敗する。

参考:MongoDBとブラウザだけで旅の記録をつけてみるか

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?