Reputation: 55
This is the data I have in the database:
{
"_id" : ObjectId("5bf84d5eb6655873af59ead6"),
"game" : 1.0,
"action" : {
"actionType" : "GameStart",
"actionNumber" : 0.0,
"Player1" : {
"user" : 2.0,
"name" : "Kevin"
},
"Player2" : {
"user" : 4.0,
"name" : "Sue"
}
}
}
The question is to report the total number of started games. I tried this code db.hw6.count({'action.actionType': "GameStart" })
, and got an error. I have no idea how I did it wrong. can anyone help?
Upvotes: 0
Views: 679
Reputation: 21
Please use itcount()
instead of count to solve the error.
It is because you are using Azure CosmosDB rather than MongoDB. count()
will work for mongodb but in your case you should use itcount()
which is CosmosDB implementation.
Please refer mongodb documentation. https://docs.mongodb.com/manual/reference/method/cursor.itcount/
Below error will be resolved after using itcount()******
Error: count failed: { "_t" : "OKMongoResponse", "ok" : 0, "code" : 13, "errmsg" : "Cannot execute command ExecuteJavaScript using PrimaryReadonlyMasterKey", "$err" : "Cannot execute command ExecuteJavaScript using PrimaryReadonlyMasterKey" } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DBQuery.prototype.count@src/mongo/shell/query.js:383:11 DBCollection.prototype.count@src/mongo/shell/collection.js:1700:12 @(shell):
Upvotes: 2