今はできない。代わりの方法。brew install mongodb
brew tap mongodb/brew brew install mongodb-community cat /usr/local/etc/mongod.conf systemLog: destination: file path: /usr/local/var/log/mongodb/mongo.log logAppend: true storage: dbPath: /usr/local/var/mongodb net: bindIp: 127.0.0.1
brew services start mongodb-community
sudo yum install -y mongodb-org
sudo systemctl start mongod
mongo
use test
show dbs
db.stats()
# db.createCollection('hello')
show collections
db.hello.stats()
db.hello.insert({'uid':123, 'test':'World'})
db.hello.insert({'uid':"oreore", 'text':'This is a pen.'})
db.hello.insert({'uid':"you", 'text':'Today is ...'})
db.hello.find()
db.hello.findOne()
db.hello.findOne()["uid"]
var r = db.hello.find()
while (r.hasNext()) printjson(r.next())
quit()
mongodump -d test mongo use test db.hello.drop() db.dropDatabase() show dbs quit() mongorestore ./dump
mongotop mongostat
db.hello.find({}, {uid: 1, text: 1, _id: 0})
db.hello.find({$or: [{'uid':123}, {'uid':"you"}]}, {uid: 1, text: 1, _id: 0})
db.hello.find({$or: [{'uid':123}, {'uid':"you"}, {'uid':"oreore"}]}, {ud: 1, text: 1, _id: 0})
db.hello.find({$or: [{'uid':123}, {'uid':"you"}, {'uid':"NO"}]}, {uid: 1, text: 1, _id: 0})
db.hello.update({"uid" : "you"}, {$set : {"text":"こんにちは"}})
db.hello.insert({'uid':"me", 'hist':[{'ymd':20201020,'val':12}]})
db.hello.update({'uid':"me"}, {$push:{'hist':{'ymd':20201024,'val':38}}})
db.hello.update({'uid':"me"}, {$set:{'last-update':ISODate("2020-10-24T12:55:15")}})
テストスクリプト:pip install pymongo
from pymongo import MongoClient
import datetime
dt_now = datetime.datetime.now()
client = MongoClient('localhost',27017)
db = client.test
col = db.hello
for i in col.find():
print(i)
col.update_one({'uid':"me"}, {
'$push':{'hist':{'ymd':dt_now,'val':189}},
'$set':{'last-update':dt_now}
})
print(col.find_one({'uid':"me"}))