Mongodb drop duplicate
It used to be one command prior to mongodb v.3.0. However, dropDup
is gone forever.
So it’s the best to just dump
and db.dropDatabase()
then mongorestore
just data
> db.col.createIndex({"vehicle_id": 1, "gps_timestamp": -1}, {"unique": true})
$ mongorestore --collection <col> --db <db> dump/***/***.bson
Mongo $geo spatial
หาจุดรอบ ๆ อนุเสาวรีย์ 3 km
q = {'point': {'$geoWithin': {'$centerSphere': [ [100.538294, 13.764923], 3/6378.1] }}}
จริงๆ มันคือ
{
<location field>: {
$geoWithin: { $centerSphere: [ [ <x>, <y> ], <radius> ] }
}
}
radius มันคือ เป็น radian คือ ถ้าจะใช้ miles ก็ x / 3,963.2 miles หรือ x / 6,378.1 kilometers
จริงๆ มันคือ The equatorial radius of the Earth is approximately 3,963.2 miles or 6,378.1 kilometers.
Note $centerSphere
Users
สร้าง User
db.createUser({user: 'sipp11', pwd: 'พาสเวิร์ดบ้านๆ', roles: ['dbAdmin', 'readWrite']})
ถ้า role ไม่เป็น object
ก็จะเป็นของ database นั้นๆ
ให้สิทธิโดยที่ไม่ทับกับสิทธิเดิม
db.grantRolesToUser("sipp11", [{db: "prediction", "role": "readWrite"}, {db:"prediction": "role": "dbAdmin"}])
แก้ไขข้อมูล – ก็ขึ้นกับว่าใน object จะ update ไรบ้างก็ใส่ไป
db.updateUser("sipp11", {"pwd": "พาสเวิดใหม่", roles: [....]})