MongoDB试用记录

MongoDB试用记录

MongoDB是一种著名的NoSQL数据库。

操作系统:RHEL5.4

MongoDB版本:2.0.0

 

下载MonoDB并解压

[root@sunrise16 setup]# wget "http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.0.tgz"
--2011-10-20 12:56:36--  http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.0.tgz
正在解析主机 fastdl.mongodb.org... 216.137.45.220, 216.137.45.22, 216.137.45.29, ...
Connecting to fastdl.mongodb.org|216.137.45.220|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:37949452 (36M) [application/x-tar]
Saving to: `mongodb-linux-i686-2.0.0.tgz'

100%[==========================================================================================>] 37,949,452  44.6K/s   in 8m 6s  

2011-10-20 13:04:44 (76.2 KB/s) - `mongodb-linux-i686-2.0.0.tgz' saved [37949452/37949452]

[root@sunrise16 setup]#

 

[root@sunrise16 setup]# tar zxf mongodb-linux-i686-2.0.0.tgz
[root@sunrise16 setup]# cd mongodb-linux-i686-2.0.0
[root@sunrise16 mongodb-linux-i686-2.0.0]# ls
bin  GNU-AGPL-3.0  README  THIRD-PARTY-NOTICES
[root@sunrise16 mongodb-linux-i686-2.0.0]# cd bin
[root@sunrise16 bin]# ls
bsondump  mongo  mongod  mongodump  mongoexport  mongofiles  mongoimport  mongorestore  mongos  mongosniff  mongostat  mongotop

 

启动mongod

[root@sunrise16 bin]# ./mongod
./mongod --help for help and startup options
Thu Oct 20 13:05:23
Thu Oct 20 13:05:23 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 20 13:05:23
Thu Oct 20 13:05:23 [initandlisten] MongoDB starting : pid=29178 port=27017 dbpath=/data/db/ 32-bit host=sunrise16
Thu Oct 20 13:05:23 [initandlisten]
Thu Oct 20 13:05:23 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 20 13:05:23 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 20 13:05:23 [initandlisten] **       with --journal, the limit is lower
Thu Oct 20 13:05:23 [initandlisten]
Thu Oct 20 13:05:23 [initandlisten] db version v2.0.0, pdfile version 4.5
Thu Oct 20 13:05:23 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Thu Oct 20 13:05:23 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Thu Oct 20 13:05:23 [initandlisten] options: {}
Thu Oct 20 13:05:23 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
Thu Oct 20 13:05:23 dbexit:
Thu Oct 20 13:05:23 [initandlisten] shutdown: going to close listening sockets...
Thu Oct 20 13:05:23 [initandlisten] shutdown: going to flush diaglog...
Thu Oct 20 13:05:23 [initandlisten] shutdown: going to close sockets...
Thu Oct 20 13:05:23 [initandlisten] shutdown: waiting for fs preallocator...
Thu Oct 20 13:05:23 [initandlisten] shutdown: closing all files...
Thu Oct 20 13:05:23 [initandlisten] closeAllFiles() finished
Thu Oct 20 13:05:23 dbexit: really exiting now
[root@sunrise16 bin]#

根据屏幕上输出的信息,克制没有创建/data/db/目录。

 

[root@sunrise16 bin]# mkdir -p /data/db/
[root@sunrise16 bin]# ./mongod         
./mongod --help for help and startup options
Thu Oct 20 13:06:31
Thu Oct 20 13:06:31 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 20 13:06:31
Thu Oct 20 13:06:31 [initandlisten] MongoDB starting : pid=29510 port=27017 dbpath=/data/db/ 32-bit host=sunrise16
Thu Oct 20 13:06:31 [initandlisten]
Thu Oct 20 13:06:31 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 20 13:06:31 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 20 13:06:31 [initandlisten] **       with --journal, the limit is lower
Thu Oct 20 13:06:31 [initandlisten]
Thu Oct 20 13:06:31 [initandlisten] db version v2.0.0, pdfile version 4.5
Thu Oct 20 13:06:31 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Thu Oct 20 13:06:31 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Thu Oct 20 13:06:31 [initandlisten] options: {}
Thu Oct 20 13:06:31 [websvr] admin web console waiting for connections on port 28017
Thu Oct 20 13:06:31 [initandlisten] waiting for connections on port 27017

 

Ctrl+C
Thu Oct 20 13:06:40 got kill or ctrl c or hup signal 2 (Interrupt), will terminate after current cmd ends
Thu Oct 20 13:06:40 [interruptThread] now exiting
Thu Oct 20 13:06:40 dbexit:
Thu Oct 20 13:06:40 [interruptThread] shutdown: going to close listening sockets...
Thu Oct 20 13:06:40 [interruptThread] closing listening socket: 5
Thu Oct 20 13:06:40 [interruptThread] closing listening socket: 6
Thu Oct 20 13:06:40 [interruptThread] closing listening socket: 7
Thu Oct 20 13:06:40 [interruptThread] removing socket file: /tmp/mongodb-27017.sock
Thu Oct 20 13:06:40 [interruptThread] shutdown: going to flush diaglog...
Thu Oct 20 13:06:40 [interruptThread] shutdown: going to close sockets...
Thu Oct 20 13:06:40 [interruptThread] shutdown: waiting for fs preallocator...
Thu Oct 20 13:06:40 [interruptThread] shutdown: closing all files...
Thu Oct 20 13:06:40 [interruptThread] closeAllFiles() finished
Thu Oct 20 13:06:40 [interruptThread] shutdown: removing fs lock...
Thu Oct 20 13:06:40 dbexit: really exiting now
[root@sunrise16 bin]#

 

 

[root@sunrise16 bin]# ./mongod --journal
Thu Oct 20 13:06:50 [initandlisten] MongoDB starting : pid=29519 port=27017 dbpath=/data/db/ 32-bit host=sunrise16
Thu Oct 20 13:06:50 [initandlisten]
Thu Oct 20 13:06:50 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 20 13:06:50 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 20 13:06:50 [initandlisten] **       with --journal, the limit is lower
Thu Oct 20 13:06:50 [initandlisten]
Thu Oct 20 13:06:50 [initandlisten] db version v2.0.0, pdfile version 4.5
Thu Oct 20 13:06:50 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Thu Oct 20 13:06:50 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Thu Oct 20 13:06:50 [initandlisten] options: { journal: true }
Thu Oct 20 13:06:50 [initandlisten] journal dir=/data/db/journal
Thu Oct 20 13:06:50 [initandlisten] recover : no journal files present, no recovery needed
Thu Oct 20 13:06:51 [initandlisten] preallocateIsFaster=true 7.24
Thu Oct 20 13:06:51 [initandlisten] preallocateIsFaster=true 7.26
Thu Oct 20 13:06:53 [initandlisten] preallocateIsFaster=true 7.22
Thu Oct 20 13:06:53 [initandlisten] preallocating a journal file /data/db/journal/prealloc.0
Thu Oct 20 13:07:58 [initandlisten] preallocating a journal file /data/db/journal/prealloc.1
                220200960/268435456     82%
Thu Oct 20 13:09:03 [initandlisten] preallocating a journal file /data/db/journal/prealloc.2
                146800640/268435456     54%
                188743680/268435456     70%
                251658240/268435456     93%
Thu Oct 20 13:10:08 [initandlisten] waiting for connections on port 27017
Thu Oct 20 13:10:08 [websvr] admin web console waiting for connections on port 28017
Thu Oct 20 13:11:08 [clientcursormon] mem (MB) res:12 virt:102 mapped:0

 

下面的日志内容是在启动一个mongo客户端之后产生的。
Thu Oct 20 13:11:50 [initandlisten] connection accepted from 127.0.0.1:36877 #1
Thu Oct 20 13:14:41 [FileAllocator] allocating new datafile /data/db/test.ns, filling with zeroes...
Thu Oct 20 13:14:41 [FileAllocator] creating directory /data/db/_tmp
Thu Oct 20 13:14:45 [FileAllocator] done allocating datafile /data/db/test.ns, size: 16MB,  took 4.083 secs
Thu Oct 20 13:14:45 [FileAllocator] allocating new datafile /data/db/test.0, filling with zeroes...
Thu Oct 20 13:14:49 [FileAllocator] done allocating datafile /data/db/test.0, size: 16MB,  took 4.07 secs
Thu Oct 20 13:14:49 [FileAllocator] allocating new datafile /data/db/test.1, filling with zeroes...
Thu Oct 20 13:14:49 [conn1] build index test.foo { _id: 1 }
Thu Oct 20 13:14:49 [conn1] build index done 0 records 0.361 secs
Thu Oct 20 13:14:51 [conn1] insert test.foo 10673ms
Thu Oct 20 13:14:57 [FileAllocator] done allocating datafile /data/db/test.1, size: 32MB,  took 8.389 secs
Thu Oct 20 13:15:17 [clientcursormon] mem (MB) res:13 virt:199 mapped:32
Thu Oct 20 13:16:46 [FileAllocator] allocating new datafile /data/db/mydb.ns, filling with zeroes...
Thu Oct 20 13:16:51 [FileAllocator] done allocating datafile /data/db/mydb.ns, size: 16MB,  took 4.262 secs
Thu Oct 20 13:16:51 [FileAllocator] allocating new datafile /data/db/mydb.0, filling with zeroes...
Thu Oct 20 13:16:55 [FileAllocator] done allocating datafile /data/db/mydb.0, size: 16MB,  took 4.06 secs
Thu Oct 20 13:16:55 [FileAllocator] allocating new datafile /data/db/mydb.1, filling with zeroes...
Thu Oct 20 13:16:55 [conn1] build index mydb.things { _id: 1 }
Thu Oct 20 13:16:55 [conn1] build index done 0 records 0 secs
Thu Oct 20 13:16:55 [conn1] insert mydb.things 8330ms
Thu Oct 20 13:17:03 [FileAllocator] done allocating datafile /data/db/mydb.1, size: 32MB,  took 8.142 secs
Thu Oct 20 13:17:23 [clientcursormon] mem (MB) res:13 virt:263 mapped:64
Thu Oct 20 13:22:23 [clientcursormon] mem (MB) res:13 virt:263 mapped:64
Thu Oct 20 13:24:08 [conn1] end connection 127.0.0.1:36877

Ctrl+C
Thu Oct 20 13:24:31 got kill or ctrl c or hup signal 2 (Interrupt), will terminate after current cmd ends
Thu Oct 20 13:24:31 [interruptThread] now exiting
Thu Oct 20 13:24:31 dbexit:
Thu Oct 20 13:24:31 [interruptThread] shutdown: going to close listening sockets...
Thu Oct 20 13:24:31 [interruptThread] closing listening socket: 6
Thu Oct 20 13:24:31 [interruptThread] closing listening socket: 7
Thu Oct 20 13:24:31 [interruptThread] closing listening socket: 8
Thu Oct 20 13:24:31 [interruptThread] removing socket file: /tmp/mongodb-27017.sock
Thu Oct 20 13:24:31 [interruptThread] shutdown: going to flush diaglog...
Thu Oct 20 13:24:31 [interruptThread] shutdown: going to close sockets...
Thu Oct 20 13:24:31 [interruptThread] shutdown: waiting for fs preallocator...
Thu Oct 20 13:24:31 [interruptThread] shutdown: lock for final commit...
Thu Oct 20 13:24:31 [interruptThread] shutdown: final commit...
Thu Oct 20 13:24:31 [interruptThread] shutdown: closing all files...
Thu Oct 20 13:24:31 [interruptThread] closeAllFiles() finished
Thu Oct 20 13:24:31 [interruptThread] journalCleanup...
Thu Oct 20 13:24:31 [interruptThread] removeJournalFiles
Thu Oct 20 13:24:31 [interruptThread] shutdown: removing fs lock...
Thu Oct 20 13:24:31 dbexit: really exiting now
[root@sunrise16 bin]#
[root@sunrise16 bin]#

 

 

使用mongo命令行工具访问MongoDB

[root@sunrise16 bin]# ./mongo
MongoDB shell version: 2.0.0
connecting to: test
Thu Oct 20 13:07:54 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
[root@sunrise16 bin]# ./mongo
MongoDB shell version: 2.0.0
connecting to: test
Thu Oct 20 13:08:19 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
[root@sunrise16 bin]# ./mongo
MongoDB shell version: 2.0.0
connecting to: test
Thu Oct 20 13:08:29 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed

 


[root@sunrise16 bin]# ./mongo
MongoDB shell version: 2.0.0
connecting to: test

> help
        db.help()                    help on db methods
        db.mycoll.help()             help on collection methods
        rs.help()                    help on replica set methods
        help admin                   administrative help
        help connect                 connecting to a db help
        help keys                    key shortcuts
        help misc                    misc things to know
        help mr                      mapreduce

        show dbs                     show database names
        show collections             show collections in current database
        show users                   show users in current database
        show profile                 show most recent system.profile entries with time >= 1ms
        show logs                    show the accessible logger names
        show log [name]              prints out the last segment of log in memory, 'global' is default
        use <db_name>                set current database
        db.foo.find()                list objects in collection foo
        db.foo.find( { a : 1 } )     list objects in foo where a == 1
        it                           result of the last line evaluated; use to further iterate
        DBQuery.shellBatchSize = x   set default number of items to display on shell
        exit                         quit the mongo shell

 

下面的测试内容来自 http://www.mongodb.org/display/DOCS/Quickstart+Unix

> db.foo.save({x:1})
> db.foo.find()
{ "_id" : ObjectId("4e9fae4127ed834a3f8d3b1a"), "x" : 1 }

 

下面的测试内容来自 http://www.mongodb.org/display/DOCS/Tutorial
> use mydb
switched to db mydb
> j={name:'zhy'}
{ "name" : "zhy" }
> t={t:3}
{ "t" : 3 }
> db.things.save(j)
> db.things.save(t)
> db.things.find()
{ "_id" : ObjectId("4e9faebe27ed834a3f8d3b1b"), "name" : "zhy" }
{ "_id" : ObjectId("4e9faecf27ed834a3f8d3b1c"), "t" : 3 }
> for (var i = 1; i <= 20; i++) db.things.save({x : 4, j : i});
> db.things.find()
{ "_id" : ObjectId("4e9faebe27ed834a3f8d3b1b"), "name" : "zhy" }
{ "_id" : ObjectId("4e9faecf27ed834a3f8d3b1c"), "t" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1d"), "x" : 4, "j" : 1 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1e"), "x" : 4, "j" : 2 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1f"), "x" : 4, "j" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b20"), "x" : 4, "j" : 4 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b21"), "x" : 4, "j" : 5 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b22"), "x" : 4, "j" : 6 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b23"), "x" : 4, "j" : 7 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b24"), "x" : 4, "j" : 8 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b25"), "x" : 4, "j" : 9 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b26"), "x" : 4, "j" : 10 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b27"), "x" : 4, "j" : 11 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b28"), "x" : 4, "j" : 12 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b29"), "x" : 4, "j" : 13 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2a"), "x" : 4, "j" : 14 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2b"), "x" : 4, "j" : 15 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2c"), "x" : 4, "j" : 16 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2d"), "x" : 4, "j" : 17 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2e"), "x" : 4, "j" : 18 }
has more
> it
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2f"), "x" : 4, "j" : 19 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b30"), "x" : 4, "j" : 20 }
> it
no cursor
> var cursor = db.things.find();
> while (cursor.hasNext()) printjson(cursor.next());
{ "_id" : ObjectId("4e9faebe27ed834a3f8d3b1b"), "name" : "zhy" }
{ "_id" : ObjectId("4e9faecf27ed834a3f8d3b1c"), "t" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1d"), "x" : 4, "j" : 1 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1e"), "x" : 4, "j" : 2 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1f"), "x" : 4, "j" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b20"), "x" : 4, "j" : 4 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b21"), "x" : 4, "j" : 5 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b22"), "x" : 4, "j" : 6 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b23"), "x" : 4, "j" : 7 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b24"), "x" : 4, "j" : 8 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b25"), "x" : 4, "j" : 9 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b26"), "x" : 4, "j" : 10 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b27"), "x" : 4, "j" : 11 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b28"), "x" : 4, "j" : 12 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b29"), "x" : 4, "j" : 13 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2a"), "x" : 4, "j" : 14 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2b"), "x" : 4, "j" : 15 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2c"), "x" : 4, "j" : 16 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2d"), "x" : 4, "j" : 17 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2e"), "x" : 4, "j" : 18 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2f"), "x" : 4, "j" : 19 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b30"), "x" : 4, "j" : 20 }
> db.things.find().forEach(printjson);
{ "_id" : ObjectId("4e9faebe27ed834a3f8d3b1b"), "name" : "zhy" }
{ "_id" : ObjectId("4e9faecf27ed834a3f8d3b1c"), "t" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1d"), "x" : 4, "j" : 1 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1e"), "x" : 4, "j" : 2 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1f"), "x" : 4, "j" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b20"), "x" : 4, "j" : 4 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b21"), "x" : 4, "j" : 5 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b22"), "x" : 4, "j" : 6 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b23"), "x" : 4, "j" : 7 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b24"), "x" : 4, "j" : 8 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b25"), "x" : 4, "j" : 9 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b26"), "x" : 4, "j" : 10 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b27"), "x" : 4, "j" : 11 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b28"), "x" : 4, "j" : 12 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b29"), "x" : 4, "j" : 13 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2a"), "x" : 4, "j" : 14 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2b"), "x" : 4, "j" : 15 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2c"), "x" : 4, "j" : 16 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2d"), "x" : 4, "j" : 17 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2e"), "x" : 4, "j" : 18 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2f"), "x" : 4, "j" : 19 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b30"), "x" : 4, "j" : 20 }
> var cursor = db.things.find();
> printjson(cursor[4]);
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1f"), "x" : 4, "j" : 3 }
> var arr = db.things.find().toArray();
> arr[5];
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b20"), "x" : 4, "j" : 4 }
> db.things.find({name:"mongo"}).forEach(printjson);
> db.things.find({name:"zhy"}).forEach(printjson);
{ "_id" : ObjectId("4e9faebe27ed834a3f8d3b1b"), "name" : "zhy" }
> db.things.find({x:4}).forEach(printjson);
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1d"), "x" : 4, "j" : 1 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1e"), "x" : 4, "j" : 2 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1f"), "x" : 4, "j" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b20"), "x" : 4, "j" : 4 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b21"), "x" : 4, "j" : 5 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b22"), "x" : 4, "j" : 6 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b23"), "x" : 4, "j" : 7 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b24"), "x" : 4, "j" : 8 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b25"), "x" : 4, "j" : 9 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b26"), "x" : 4, "j" : 10 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b27"), "x" : 4, "j" : 11 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b28"), "x" : 4, "j" : 12 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b29"), "x" : 4, "j" : 13 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2a"), "x" : 4, "j" : 14 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2b"), "x" : 4, "j" : 15 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2c"), "x" : 4, "j" : 16 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2d"), "x" : 4, "j" : 17 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2e"), "x" : 4, "j" : 18 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2f"), "x" : 4, "j" : 19 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b30"), "x" : 4, "j" : 20 }
> db.things.find({x:4}, {j:true}).forEach(printjson);
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1d"), "j" : 1 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1e"), "j" : 2 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1f"), "j" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b20"), "j" : 4 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b21"), "j" : 5 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b22"), "j" : 6 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b23"), "j" : 7 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b24"), "j" : 8 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b25"), "j" : 9 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b26"), "j" : 10 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b27"), "j" : 11 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b28"), "j" : 12 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b29"), "j" : 13 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2a"), "j" : 14 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2b"), "j" : 15 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2c"), "j" : 16 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2d"), "j" : 17 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2e"), "j" : 18 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b2f"), "j" : 19 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b30"), "j" : 20 }
> printjson(db.things.findOne({name:"mongo"}));
null
> printjson(db.things.findOne({name:"zhy"}));
{ "_id" : ObjectId("4e9faebe27ed834a3f8d3b1b"), "name" : "zhy" }
> var doc = db.things.findOne({_id:ObjectId("4c2209f9f3924d31102bd84a")});
> doc
null
> var doc = db.things.findOne({_id:ObjectId("4e9faf0f27ed834a3f8d3b28")});
> doc
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b28"), "x" : 4, "j" : 12 }
> db.things.find().limit(3);
{ "_id" : ObjectId("4e9faebe27ed834a3f8d3b1b"), "name" : "zhy" }
{ "_id" : ObjectId("4e9faecf27ed834a3f8d3b1c"), "t" : 3 }
{ "_id" : ObjectId("4e9faf0f27ed834a3f8d3b1d"), "x" : 4, "j" : 1 }
> quit
function () {
    return nativeHelper.apply(quit_, arguments);
}
> exit
bye
[root@sunrise16 bin]#

 

Studio 3T无限试用:解锁MongoDB可视化工具的完整功能 本文详细介绍了如何通过无限试用方法解锁Studio 3T的完整功能,这是一款强大的MongoDB可视化工具。文章涵盖了安装配置、试用期重置原理及操作步骤,以及SQL转换、聚合管道构建等高级功能实战演示,帮助开发者高效管理MongoDB数据库。 阅读详情

相关推荐

实战演练:用wvp-GB28181-pro + ZLMediaKit搭建一个可用的国标视频监控测试环境(附设备模拟器对接)

本文详细介绍了如何使用wvp-GB28181-pro和ZLMediaKit在Ubuntu系统上搭建GB28181视频监控测试环境。从环境准备、组件解析到核心服务部署与设备模拟器对接,提供完整的实战指南,帮助开发者快速构建可验证的监控系统。

weixin_42692935的博客 589

正在解析主机……失败:未知的名称或服务,wget无法解析主机地址。

无法解析主机地址 在centos7系统中安装python3时出现:无法解析主机地址问题 wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz 正在解析主机 www.python.org (www.python.org)… 失败:未知的名称或服务。 wget: 无法解析主机地址 “www.python.org” 1、打开终...

qq_44739762的博客 2万+

PaddleOCR训练自己的数据

一 、数据准备 采用PPOCRLabel标注自己的数据 PPOCRLabel是一款适用于OCR领域的半自动化图形标注工具,内置PP-OCR模型对数据自动标注和重新识别。使用Python3和PyQT5编写,支持矩形框标注和四点标注模式,导出格式可直接用于PaddleOCR检测和识别模型的训练。 1.1 安装PaddlePaddle pip3 install --upgrade pip # 如果您的机器安装的是CUDA9或CUDA10,请运行以下命令安装 python3 -m pip in.

zyb的博客 1万+

centos7安装mongodb

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33737774的博客 179

什么是三极管推挽电路

当没有信号输入时,电源通过PNP三极管EB间的二极管,然后通过NPN三极管BE间而二极管到地,这时这两个三极管都是导通的,三极管很容易由于电流过大而损坏。当输入信号为VCC时,上面的三极管导通,下面的三极管截止,输出信号为VCC-0.7V,这个0.7V就是上面NPN三极管BE间的导通压降。比如上面的三极管导通,那么输出电压就是输入电压减去0.7V,所以下面的PNP三极管由于基极电压大于发射极电压,是不会导通的。这是一个三极管推挽电路,上面是一个NPN的三极管,下面是一个PNP的三极管。

谢谢关注“小鱼教你模数电”,各平台同号 3382

手把手教你用树莓派蓝牙抓取小米温湿度计2代数据,接入HomeAssistant(附密钥获取避坑指南)

本文详细介绍了如何通过树莓派蓝牙抓取小米温湿度计2代数据并接入HomeAssistant的完整流程。重点解析了获取32位加密密钥的三种方法,包括使用Telink Flasher工具、米家APP抓包和开源工具ATC_MiThermometer,并提供了HomeAssistant集成配置和常见问题排查指南,帮助用户实现稳定可靠的温湿度监测。

一名菜鸟攻城师 794

mongodb学习笔记(一)

一个菜鸟,开始mongodb的学习之路

fy1995612的专栏 922

Kettle 连接 Oracle 数据库全流程指南

例如:C:\Oracle\product\19.0.0\dbhome_1\jdbc\lib\ojdbc8.jar 2. 替换 Kettle 驱动文件 将驱动文件复制到 Kettle 的 目录: 删除旧版本驱动:如 ojdbc14.jar 只能保留一个oracle驱动 重启 Kettle 以加载新驱动 二、配置数据库连接 1. 启动 Kettle 并新建转换 运行 (Windows)或 (Linux)。 新建转换(Transformation),添加 “表输入” 步骤,双击进入配置。 2.

qq_44724453的博客 3493

MongoDB 安装

bash-4.2$ su密码:[root@dbserver latte]# mkdir /usr/local/MongoDB[root@dbserver latte]# cd /usr/local/src[root@dbserver src]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.0.tgz--...

熊佳佳的技术笔记 314

告别算力焦虑:手把手教你用华为CloudMatrix384超节点部署MoE大模型(附xDeepServe配置)

本文详细解析了如何在华为CloudMatrix384超节点上高效部署MoE大模型,通过xDeepServe框架配置和专家分配优化,实现2300 Tokens/s的推理吞吐。文章涵盖环境准备、性能调优、成本平衡及容灾设计,帮助开发者告别算力焦虑,提升AI推理效率。

weixin_30790841的博客 450

03.Linux下目录动态扩容,以分配home的部分空间给root为例

本篇文章将介绍Linux下分配home目录的部分空间给root目录。大致思路:卸载home,解除其磁盘容量占用->扩容root,增加其磁盘空间->重建恢复home操作演示环境为CentOS系统,其他操作系统例如openEuler也可作为参考。01.Linux下目录扩容,以增加root目录的磁盘容量分配为例操作系统版本如下名称版本CentOS7.6+

ChennyWJS的博客 2339

maven spring 整合mongoDb

突然来了需求 想用mongodb做聚合 于是赶紧谷百 但是过程却很艰苦 发现网上有很多 但是自己搭建起来不是版本错误就是权限不足 从网上爬取下来的有很多错误 所有决定记录下,初次使用mongodb 有很多问题,请留言交流。 mongdb使用的jar包版本 &lt;properties&gt; &lt;!--mongodb--&gt; &lt;mongodb_version&...

Artoro的博客 1142

新手必看:C#调用YOLO模型完成图片/视频目标检测(上位机版)

新手学习C#调用YOLO模型,核心是先把基础流程跑通,再逐步优化。图片检测是基础,视频检测就是在图片的基础上加循环和线程,而上位机的实际项目,就是在这个基础上适配工业硬件和业务需求。本文的代码都是新手能直接复制运行的,如果你运行时遇到问题,先检查前期准备是否到位,再看避坑指南。记住,新手别追求一步到位,先实现功能,再慢慢优化性能和界面。等你能熟练调用YOLO模型后,再去研究模型训练、量化优化等进阶内容,会轻松很多。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 993

testRigor测试用例模板记录

testRigor测试用例模板记录。

qq_30464221的博客 798

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

工作随机记录

前言: 用了段时间。mongodb 很多记录都是不全面的。这里只是做个记录。方便以后查看 正文: 启动服务:mongod 客户端:mongo

u012762054的博客 310

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

孤荷凌寒自学python第五十五天初识MongoDb数据库

孤荷凌寒自学python第五十五天第一天初识MongoDb数据库 (完整学习过程屏幕记录视频地址在文末) 大家好,2019年新年快乐! 本来我想的是借新年第一天开始,正式尝试学习爬虫,结果今天偶然发现还有一种被更广泛使用的Nosql数据库,而且还可以在本地建构本地化的数据库服务,这就是大名鼎鼎的:mongoDB 首先访问:https://www.mongodb.com/z...

weixin_30596735的博客 152

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

SpringBoot学习笔记(九:MongoDB )

还有Java核心知识点+全套架构师学习资料和视频+一线大厂面试宝典+面试简历模板可以领取+阿里美团网易腾讯小米爱奇艺快手哔哩哔哩面试题+Spring源码合集+Java架构实战电子书+2021年最新大厂面试题。《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

2401_83329402的博客 1111

Spring boot学习之MongoDB的使用

Spring boot学习之MongoDB的使用 Mongodb在做一些个人的小项目的时候我觉得还是挺不错的,因为是nosql的数据库,结合jpa使用可以做到不需要建表不需要写sql语句的效果,对于需要数据存储的小项目来说其实是很合适的。 接下来就来简单介绍一下MongoDb结合Springboot的一些基础使用,这里使用的Springboot版本是2.3.7.RELEASE,别的版本可能有些许不同,自行查找别的教程 废话少说我们直接来实战上手 第一步:导入依赖 <dependency&gt

q1763868326的博客 307

spring使用MongodbTemplate操作mongodb 数据库

1.application.properties添加配置 #MongoDb 数据库操作 spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.authentication-database=admin spring.data.mongodb.database=test spring.data.mongodb.username=manag spring.data.mongodb.pass

frankgy01的专栏 1485

mongodb基础3

mongodb和java 加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> 加配置 spring: data: mongodb:

耗子窝 295

MongoDB学习日记 - Spring框架集成 : spring-data-mongodb

一直想写这部分,但是由于水平太差了,一直没敢写;今天就献丑把自己的实践写一下,自己以后实际开发也可以回头看看。这里贴的代码都是自己测试真实的代码。下载地址:百度云分享(spring-mongo.rar)

Duanc 的博客 1887

mongo在M1 Pro中的使用踩坑记录及解决

1.首先安装我建议使用homebrew安装,具体的教程网上应该有很多。但这里我重点介绍一下用安装包自己手动安装,首先是MongoDB网站的页面:此处需要注意:一定要下载的(我指的是m1 pro用户,其实只要是苹果芯片都应该是arm64)2.下载下来之后,双击进行一个解压(如果是新电脑可能不支持解压tgz的压缩包,你可以选择下载zip,当然你可以下载一下我的这个解压工具),激活码是9kpg,如果链接已失效,请联系我!

Alaiks的博客 152

mongodb分组查询 php,php – 按字段分组在MongoDB中不起作用

我正在尝试计算我的数据库中所有记录的总和,我需要避免重复.我写了这段代码来对记录进行分组,但它对我不起作用.$pipeline = [['$match' =>$criteria->getCondition()],['$group' =>['_id' => '$order_id','total' => ['$sum' => '$'.$column]]]];$thi...

weixin_32921023的博客 272

MongoDB 文档被delete后,如何回收磁盘空间?

在回答这个问题之前,先了解一下 MySQL InnoDB 存储引擎是如何回收磁盘空间的。假设有一张表包含 1000 万条记录,删除其中的 800 万条记录,此时 InnoDB 的磁盘空间不会自动释放。要回收磁盘空间,需要执行以下命令:登录后复制 ALTER TABLE tableName ENGINE=InnoDB;1....

weixin_32063287的博客 262

红队知识学习入门(3)Shodan使用5

学习视频来自B站UP主 泷羽sec,如涉及侵泷羽sec权马上删除文章笔记的只是方便各位师傅学习知识,以下网站涉及学习内容,其他的都与本人无关,切莫逾越法律红线,否则后果自负

Zeu_s的博客 826

MongoDB 试用

部分内容摘自 http://www.runoob.com/mongodb/mongodb-tutorial.html 什么是MongoDB ? MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统。 在高负载的情况下,添加更多的节点,可以保证服务器性能。 MongoDB 旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB

王鹏亮 的专栏 3697
上一篇: Bash字符串处理(与Java对照) - 20.查找子串的位置
下一篇: 好资料推荐:Linux 101 Hacks 英文原版+中文版PDF下载
codingstandards
博客等级 码龄16年 12粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值