Я новичок в MongoDB.
Просто создал коллекцию с именем datasets
и вставил в нее один большой json.
Документ:
{
"_id":ObjectId( "5e1f2b248eebbe6d289d53c6" ),
"countries":{
"country":[
{
"area":9596960,
"cities":{
"city":[
{
"citypopulation":7830000,
"cityname":"Shanghai"
},
{
"citypopulation":7000000,
"cityname":"Beijing"
},
{
"citypopulation":6218000,
"cityname":"HongKong"
},
{
"citypopulation":5770000,
"cityname":"Tianjin"
},
{
"citypopulation":4540000,
"cityname":"Shenyang"
},
{
"citypopulation":3750000,
"cityname":"Wuhan"
},
{
"citypopulation":3580000,
"cityname":"Guangzhou"
},
{
"citypopulation":2980000,
"cityname":"Chongqing"
},
{
"citypopulation":2830000,
"cityname":"Harbin"
},
{
"citypopulation":2810000,
"cityname":"Chengdu"
},
{
"citypopulation":2760000,
"cityname":"Xian"
},
{
"citypopulation":2500000,
"cityname":"Nanjing"
},
{
"citypopulation":2460000,
"cityname":"Zibo"
},
{
"citypopulation":2400000,
"cityname":"Dalian"
},
{
"citypopulation":2320000,
"cityname":"Jinan"
},
{
"citypopulation":2110000,
"cityname":"Changchun"
},
{
"citypopulation":2060000,
"cityname":"Qingdao"
},
{
"citypopulation":1960000,
"cityname":"Taiyuan"
},
{
"citypopulation":1710000,
"cityname":"Zhengzhou"
},
{
"citypopulation":1530000,
"cityname":"Guiyang"
},
{
"citypopulation":1520000,
"cityname":"Kunming"
},
{
"citypopulation":1510000,
"cityname":"Lanzhou"
},
{
"citypopulation":1500000,
"cityname":"Tangshan"
},
{
"citypopulation":1390000,
"cityname":"Anshan"
},
{
"citypopulation":1380000,
"cityname":"Qiqihar"
},
{
"citypopulation":1350000,
"cityname":"Nanchang"
},
{
"citypopulation":1350000,
"cityname":"Fushun"
},
{
"citypopulation":1340000,
"cityname":"Hangzhou"
},
{
"citypopulation":1330000,
"cityname":"Changsha"
},
{
"citypopulation":1320000,
"cityname":"Shijiazhuang"
},
{
"citypopulation":1290000,
"cityname":"Fuzhou"
},
{
"citypopulation":1270000,
"cityname":"Jilin"
},
{
"citypopulation":1200000,
"cityname":"Huainan"
},
{
"citypopulation":1200000,
"cityname":"Baotou"
},
{
"citypopulation":1190000,
"cityname":"Luoyang"
},
{
"citypopulation":1160000,
"cityname":"Urumqi"
},
{
"citypopulation":1110000,
"cityname":"Handan"
},
{
"citypopulation":1110000,
"cityname":"Datong"
},
{
"citypopulation":1090000,
"cityname":"Ningbo"
},
{
"citypopulation":1070000,
"cityname":"Nanning"
},
{
"citypopulation":1000000,
"cityname":"Hefei"
}
]
},
"name":"China",
"population":1210004992
},
{
"area":3287590,
"cities":{
"city":[
{
"citypopulation":9925891,
"cityname":"Mumbai"
},
{
"citypopulation":7206704,
"cityname":"NewDelhi"
},
{
"citypopulation":4399819,
"cityname":"Calcutta"
},
{
"citypopulation":3841396,
"cityname":"Madras"
},
{
"citypopulation":3302296,
"cityname":"Bangalore"
},
{
"citypopulation":3145939,
"cityname":"Hyderabad"
},
{
"citypopulation":2954526,
"cityname":"Ahmadabad"
},
{
"citypopulation":1879420,
"cityname":"Kanpur"
},
{
"citypopulation":1624752,
"cityname":"Nagpur"
},
{
"citypopulation":1619115,
"cityname":"Lucknow"
},
{
"citypopulation":1566651,
"cityname":"Pune"
},
{
"citypopulation":1505872,
"cityname":"Surat"
},
{
"citypopulation":1458183,
"cityname":"Jaipur"
},
{
"citypopulation":1091674,
"cityname":"Indore"
},
{
"citypopulation":1062771,
"cityname":"Bhopal"
},
{
"citypopulation":1061598,
"cityname":"Vadodara"
},
{
"citypopulation":1042740,
"cityname":"Ludhiana"
},
{
"citypopulation":1014557,
"cityname":"Kalyan"
}
]
},
"name":"India",
"population":952107712
}
]
}
}
Я хочу знать, какие типы операций поиска я могу сделать, чтобы выбрать эту json запись для целей обучения ..?
Я пытался запустить ниже операцию поиска, в результате ничего не получается.
db.datasets.find({'name':'China'})
Во-вторых, я добавил выше json в datasets
коллекциях, используя следующую команду
mongoimport --db admin --collection datasets --file /home/lenny/TransformedJSON.json
Работает нормально, но я хочу не выполнить эту команду. Потому что я не хочу вставлять без имени пользователя и пароля. Как это можно сделать?
Кто-нибудь может подсказать, пожалуйста ..?