Chapter 5 - not able to create views or find views

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.system.views.find().pretty()
Error: error: {
“operationTime” : Timestamp(1544309371, 1),
“ok” : 0,
“errmsg” : “not authorized on aggregations to execute command { find: “system.views”, filter: {}, lsid: { id: UUID(“7bc12405-ca2b-445b-8972-817a10624865”) }, $clusterTime: { clusterTime: Timestamp(1544309231, 1), signature: { hash: BinData(0, 13E5A732FFBE17481175D265BEE9E0163F921295), keyId: 6595588990781358081 } }, $db: “aggregations” }”,
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1544309371, 1),
“signature” : {
“hash” : BinData(0,“11qjSbu4q68LvyYrkIEuPsgBta8=”),
“keyId” : NumberLong(“6595588990781358081”)
}
}
}
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.createView(“bronze_banking”, “customers”, [
… {
… “$match”: { “accountType”: “bronze” }
… },
… {
… “$project”: {
… “_id”: 0,
… “name”: {
… “$concat”: [
… { “$cond”: [{ “$eq”: ["$gender", “female”] }, “Miss”, “Mr.”] },
… " “,
… “$name.first”,
… " “,
… “$name.last”
… ]
… },
… “phone”: 1,
… “email”: 1,
… “address”: 1,
… “account_ending”: { “$substr”: [”$accountNumber”, 7, -1] }
… }
… }
… ])
{
“operationTime” : Timestamp(1544309611, 1),
“ok” : 0,
“errmsg” : "not authorized on aggregations to execute command { create: “bronze_banking”, pipeline: [ { $match: { accountType: “bronze” } }, { $project: { _id: 0.0, name: { $concat: [ { $cond: [ { $eq: [ “$gender”, “female” ] }, “Miss”, “Mr.” ] }, " ", “$name.first”, " “, “$name.last” ] }, phone: 1.0, email: 1.0, address: 1.0, account_ending: { $substr: [ “$accountNumber”, 7.0, -1.0 ] } } } ], viewOn: “customers”, lsid: { id: UUID(“7bc12405-ca2b-445b-8972-817a10624865”) }, $clusterTime: { clusterTime: Timestamp(1544309371, 1), signature: { hash: BinData(0, D75AA349BBB8ABAF0BBF262B90812E3EC801B5AF), keyId: 6595588990781358081 } }, $db: “aggregations” }”,
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1544309611, 1),
“signature” : {
“hash” : BinData(0,“qN+4vBZaCAxN8t/e7jYNaFzl8l4=”),
“keyId” : NumberLong(“6595588990781358081”)
}
}
}
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

Hi,

Yes, the user m121 has read-only access in the aggregations database. I would suggest to import the aggregations database into a local instance if you want to experiment with views.

José Carlos

Not the same, but this at least allows you to filter on view in question for chapter 5.

db.getCollectionInfos({“type”: “view”, “name”: “bronze_banking”})

Hi,
Could you please let me know how to import the database into the local instance

Thank you,
Surekha S

https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/

I occasionally get a “not authorized” message from the mongo shell application. (this has happened to me 3 or 4 times during this course. I fix it by existing that mongo running application and restarting my connection with a new mongo command. This does not seem to be related to a long connection as this happened to me this morning with a new mongo command execution.

FYI in case restarting your ‘mongo "mongodb://cluster0-…’ might also help you move forward.

example message:
"2019-03-28T08:38:41.538-0600 E QUERY [js] Error: command failed: {
“operationTime” : Timestamp(1553783921, 1),
“ok” : 0,
“errmsg” : "not authorized on aggregation to execute command "