1
2
3
|
mongoexport -d
test
-c stu -o stu.dat
connected to: 127.0.0.1
exported 10 records
|
1
2
3
4
5
6
7
8
9
10
11
|
cat
stu.dat
{
"_id"
: 1,
"classid"
: 1,
"age"
: 14,
"name"
:
"Tom"
}
{
"_id"
: 2,
"classid"
: 1,
"age"
: 12,
"name"
:
"Jacky"
}
{
"_id"
: 3,
"classid"
: 2,
"age"
: 16,
"name"
:
"Lily"
}
{
"_id"
: 4,
"classid"
: 2,
"age"
: 9,
"name"
:
"Tony"
}
{
"_id"
: 5,
"classid"
: 2,
"age"
: 19,
"name"
:
"Harry"
}
{
"_id"
: 6,
"classid"
: 2,
"age"
: 13,
"name"
:
"Vincent"
}
{
"_id"
: 7,
"classid"
: 1,
"age"
: 14,
"name"
:
"Bill"
}
{
"_id"
: 8,
"classid"
: 2,
"age"
: 17,
"name"
:
"Bruce"
}
{
"_id"
: 9,
"classid"
: 3,
"age"
: 18,
"name"
:
"Gaici"
}
{
"_id"
: 10,
"classid"
: 3,
"age"
: 38,
"name"
:
"Leader"
}
|
1
|
mongoexport -d
test
-c stu --csv -f classid,age,name -o stu_csv.dat
|
1
2
3
4
5
6
7
8
9
10
11
12
|
cat
stu_csv.dat
classid,age,name
1.0,14.0,
"Tom"
1.0,12.0,
"Jacky"
2.0,16.0,
"Lily"
2.0,9.0,
"Tony"
2.0,19.0,
"Harry"
2.0,13.0,
"Vincent"
1.0,14.0,
"Bill"
2.0,17.0,
"Bruce"
3.0,18.0,
"Gaici"
3.0,38.0,
"Leader"
|
1
2
3
4
5
6
7
8
9
|
> db.stu.drop()
true
> show tables;
fs.chunks
fs.files
mycappc1
mycappc2
stu_res
system.indexes
|
1
2
3
|
mongoimport -d
test
-c stu stu.dat
connected to: 127.0.0.1
Tue Nov 12 17:43:16.532 imported 10 objects
|
1
|
mongoimport -d
test
-c stu -
type
csv --headerline --
file
stu_csv.dat
|
1
|
mongodump -d
test
|
1
|
mongodump -d
test
-o my_test
|
1
2
|
db.dropDatabase()
{
"dropped"
:
"test"
,
"ok"
: 1 }
|
1
|
mongorestore -d
test
dump/*
|
1
|
.
/mongod
--bind_ip 192.168.1.103
|
1
|
.
/mongod
--bind_ip 192.168.1.103 --port 28018
|
1
|
.
/mongo
192.168.1.103:28018
|
1
|
.
/mongod
--auth
|
1
2
3
4
|
.
/mongo
MongoDB shell version: 2.4.7
connecting to:
test
>
|
1
2
3
4
5
6
7
8
|
use admin
db.addUser(
'root'
,
'123'
)
{
"user"
:
"root"
,
"readOnly"
:
false
,
"pwd"
:
"c2eb464922307de3bc3aaf9593f1d49b"
,
"_id"
: ObjectId(
"5282086396b7a4a6e3cb17ed"
)
}
|
1
2
3
4
5
|
.
/mongo
-uroot -p123
test
MongoDB shell version: 2.4.7
connecting to:
test
Tue Nov 12 19:07:41.870 Error: 18 { code: 18, ok: 0.0, errmsg:
"auth fails"
} at src
/mongo/shell/db
.js:228
exception: login failed
|
1
2
3
4
5
6
7
8
9
10
11
|
> use
test
;
switched to db
test
> db.addUser(
'test'
,
'123'
,
true
)
{
"user"
:
"test"
,
"readOnly"
:
true
,
"pwd"
:
"e78333b96cbdc20a67432095f4741222"
,
"_id"
: ObjectId(
"52820d76bca929d60ae67b5c"
)
}
> db.auth(
'test'
,
'123'
)
1
|