markdown MongoDB的
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown MongoDB的相关的知识,希望对你有一定的参考价值。
`http://localhost:5000/collection?where={"timestamp": "20180101"}`
`?sort=[("total": -1)]`
`?max_results=20&page=2`
`?projection={"predict": 0}` return all but predict
`?projection={"predict": 1}` return only predict
`?embedded={"author": 1}` join-alike (converts id into embedded document)
`?where={ "status_id": { "$in": [${this.queryParams.activeStatuses.join(',')}] }, "timestamp": {"$gt": 111, "$lt": 222} }`
Enable profiling `db.setProfilingLevel(1)`
Show most recent slow query `db.system.profile.find().sort({$natural: -1}).limit(1)`
Show all indexes for DB:
```
db.getCollectionNames().forEach(function(collection) {
indexes = db[collection].getIndexes();
print("Indexes for " + collection + ":");
printjson(indexes);
});
```
An index for one of workers-cache collections
```
{
"v" : 2,
"key" : {
"cacheKey" : 1
},
"name" : "cacheKey",
"ns" : "workers-cache.emailage_mongo"
}
```
Create index: `db.COLLECTION.createIndex( { "cacheId": 1 } )`
Drop DB: `db.collection.drop()`
Get 50 random documents: `db.imported.aggregate([{ $sample: {size: 50} }])`
Update/convert timestamp in each doc:
```
db.history.find().forEach(function(doc){
doc.timestamp = new Date(doc.timestamp).getTime();
db.history.save(doc);
});
```
### Add user
```
mongo "mongodb://root:MdQKIGrUx3kRQOL7@10.10.2.81:32017/workers-cache?authSource=admin"
use workers-cache
db.createUser({ user: "worker", pwd: "MdQKIGrUx3kRQOL7", roles: [ {role: "readWrite", db: "workers-cache"}] })
```
`db.users.deleteOne({"email": "raa_ua@me.com"})`
`db.users.find({"contacts.email": "alexroman@partscout.me"}).pretty()`
`mongo 'mongodb://partscout:NExIctoGrADiCKOntipE@partscout-shard-00-00-dvsc7.mongodb.net:27017,partscout-shard-00-01-dvsc7.mongodb.net:27017,partscout-shard-00-02-dvsc7.mongodb.net:27017/partscout-staging?ssl=true&authSource=admin&replicaSet=partscout-shard-0'`
以上是关于markdown MongoDB的的主要内容,如果未能解决你的问题,请参考以下文章
markdown MongoDB的
markdown MongoDB的
markdown MongoDB的聚合
markdown MongoDB的备份
markdown MongoDB的
markdown MongoDB的