#!< 2015.11.02
https://docs.mongodb.org/getting-started/python/
db.user.find({
? ? ? ? ? ? ? ? ? ? ? ? ? $and:?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{"user_id": {$exists: true}},?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {"createtime": {$gte: "1442289375298", $lte: "1442544392813"}}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?]
? ? ? ? ? ? ? ? ? ? ? ? })
tianzhaixing@c-mini:~$ mongo
> use douban
> db.Culture.find({"bookinfo.ISBN":"9787100017664"})
{ "_id" : ObjectId("56089dee145da4e928192eb5"), "bookinfo" : { "平均評分" : "9.3", "書名" : "國史大綱(上下)", "出版社" : "商務(wù)印書館", "出版年" : "2013-8", "頁數(shù)" : "914", "定價" : "76.00元", "裝幀" : "平裝", "叢書" : "", "ISBN" : "9787100017664", "coverurl" : "http://img6.douban.com/lpic/s1034305.jpg" } }
> new Date('2015-07-01').valueOf()
1435708800000
>new Date('2015-10-16').valueOf()
1444953600000
foba:PRIMARY> db.scanbehavior.find({"type": "byBarcode"}, {'bid':{"$exists":true}}, {'createtime': {"$gt":'1445702400000', "lte": '1446307200000'} }).count()
12331
foba:PRIMARY> db.scanbehavior.find({"type": {"$ne":"byBarcode"}}, {'bid':{"$exists":true}}, {'createtime': {"$gt":'1445702400000', "lte": '1446307200000'} }).count()
20407
#!< 2015.11.03
>>> UserIdsAgents = logs.find({"$and":[{"body.user_id":{"$exists":"True"}}, {"headers.user-agent":{"$exists":"True"}}]})
>>> UserIdsAgents.count()
16934
>>> userAgentTypes = set()
>>> for cur in UserIdsAgents:
... ??? ??? userAgentTypes.add(cur['headers']['user-agent'])
...
>>> len(userAgentTypes)
14
>>> for s in userAgentTypes:
... ??? ??? print s
...
bookshelf/0.8.0 (iPhone; iOS 8.4; Scale/2.00)
bookshelf/0.8.0 (iPhone; iOS 9.1; Scale/3.00)
bookshelf/0.8.0 (iPhone; iOS 9.1; Scale/2.00)
bookshelf/0.8.0 (iPhone; iOS 9.0.2; Scale/2.00)
bookshelf/0.8.0 (iPhone; iOS 9.0; Scale/2.00)
node-superagent/1.3.0
bookshelf/0.8.0 (iPad; iOS 7.1.2; Scale/2.00)
Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36
bookshelf/0.8.0 (iPhone; iOS 9.0.2; Scale/3.00)
bookshelf/0.8.0 (iPhone; iOS 8.1; Scale/2.00)
bookshelf/0.8.0 (iPhone; iOS 8.3; Scale/2.00)
bookshelf/0.8.0 (iPhone; iOS 8.4.1; Scale/2.00)
okhttp/2.5.0
bookshelf/0.8.0 (iPod touch; iOS 9.1; Scale/2.00)
>>>
In this case, type the following command
ps wuax | grep mongo
You should see something that looks like this
User?????????? 31936?? 0.5 0.4 2719784 35624?? ?? S???? 7:34pm?? 0:09.98 mongod
User?????????? 31945?? 0.0 0.0 2423368?? 184 s000 R+?? 8:24pm?? 0:00.00 grep mongo
Now enter the kill command for the mongod instance (31936 in this case):
kill 31936
MongoDB的啟動和關(guān)閉
1. 以守護進程方式啟動
進入bin目錄
./mongod
2. 打開客戶端
./mongo
3. 關(guān)閉服務(wù)
客戶端下
db.shutdownServer()
4. 退出客戶端
exit
> 刪除當前使用數(shù)據(jù)庫 ?db.dropDatabase();
> 刪除collection
drop()?命令的基本語法如下
db.COLLECTION_NAME.drop()
MongoDB導(dǎo)出數(shù)據(jù)
$mongoexport --db douban ?--collection books --out douban9plusbooks.json
$mongoexport --host 192.168.200.20 --db bookshelf --username '***' --password '***' --collection book --out workspace/MongoDBexport/TOPin.csv
$mongoexport --host=192.168.100.3 --port=27019 --db=master --collection=data --query='{"spider":"6w"}' --fields="data.ISBN" --type=csv --out=dataISBN.csv
MongoDB拷貝數(shù)據(jù)
1 開啟mongo 服務(wù)器
$sudo mongod
password:
2 開啟mongo 客戶端
$mongo
> db.copyDatabase("douban", "douban", "192.168.1.156", "jt", "***")
3. 說明
db.copyDatabase(fromdb,todb,fromhost,username,password,mechanism)
password: 有密碼就輸入密碼,沒有就為空字符串"".
> db.collection.insert_many
>>>db.test.count()
0
>>>result=db.test.insert_many([{'x':i}foriinrange(2)])
>>>result.inserted_ids
[ObjectId('54f113fffba522406c9cc20e'), ObjectId('54f113fffba522406c9cc20f')]
>>>db.test.count()
2
.....