Mongo shell 函数详解 - 文件系统

文件系统

> pwd()

/root/.m2

> ls()

[

"./settings.xml",

"./mongo.js",

"./data.json"

]

> listFiles()

[

{

"name" : "./settings.xml",

"isDirectory" : false,

"size" : 2333

},

{

"name" : "./mongo.js",

"isDirectory" : false,

"size" : 12

},

{

"name" : "./data.json",

"isDirectory" : false,

"size" : 292

}

]

> var data = cat("./data.json")

> data.trim()

{"code":0,"data":{"country":"\u4e2d\u56fd","country_id":"CN","area":"\u534e\u4e1c","area_id":"300000","region":"\u4e0a\u6d77\u5e02","region_id":"310000","city":"\u4e0a\u6d77\u5e02","city_id":"310000","county":"","county_id":"-1","isp":"\u79fb\u52a8","isp_id":"100025","ip":"117.135.147.85"}}

> var obj = JSON.parse(data)

> obj

{

"code" : 0,

"data" : {

"country" : "中国",

"country_id" : "CN",

"area" : "华东",

"area_id" : "300000",

"region" : "上海市",

"region_id" : "310000",

"city" : "上海市",

"city_id" : "310000",

"county" : "",

"county_id" : "-1",

"isp" : "移动",

"isp_id" : "100025",

"ip" : "117.135.147.85"

}

}

> db.tmp.save(obj)

> db.tmp.findOne()

{

"_id" : ObjectId("54226ac33bffbb23d33a2cbf"),

"code" : 0,

"data" : {

"country" : "中国",

"country_id" : "CN",

"area" : "华东",

"area_id" : "300000",

"region" : "上海市",

"region_id" : "310000",

"city" : "上海市",

"city_id" : "310000",

"county" : "",

"county_id" : "-1",

"isp" : "移动",

"isp_id" : "100025",

"ip" : "117.135.147.85"

}

}

> Object.keySet(obj)

[ "code", "data", "_id" ]

> db.tmp.find()

{ "_id" : ObjectId("54226ac33bffbb23d33a2cbf"), "code" : 0, "data" : { "country" : "中国", "country_id" : "CN", "area" : "华东", "area_id" : "300000", "region" : "上海市", "region_id" : "310000", "city" : "上海市", "city_id" : "310000", "county" : "", "county_id" : "-1", "isp" : "移动", "isp_id" : "100025", "ip" : "117.135.147.85" } }

> cat("./mongo.js")

db.tmp.remove()

> load("./mongo.js")

true

> db.tmp.find()

 

mongodb shell 使用js 

http://www.habadog.com/2011/08/09/mongodb-shell-use-js/

你可能感兴趣的:(listFiles(),cat(),ls(),cd(),load())