I am attempting to shard my database, but I am having an issue with findAndModify
I have a schema that looks like this (myCollection):
{
"_id": "508206a9f6ded00c50f59469"
"DatabaseId" : 91,
"TypeId" : "5e62603c-8",
"ItemId" : "734",
"UserId" : "d14e3afd-d8b3-4c37-87cd-db5d89291c44"
}
I am setting my shardkey like this:
db.runCommand({enablesharding:"myDb"});
db.runCommand({
shardcollection: "myDb.myCollection",
key: {
"DatabaseId" : 1,
"TypeId" : 1,
"ItemId" : 1
}
});
Lets say the schema above is inserted into the database.
Now I run this query:
db.myCollection.findAndModify({
query: {
"DatabaseId" : 91,
"TypeId" : "5e62603c-8",
"ItemId" : "734",
"UserId" : "d14e3afd-d8b3-4c37-87cd-db5d89291c44"
},
remove: true
});
I get this error from running the findAndModify:
findAndModifyFailed failed: {
"errmsg" : "exception: query for sharded findAndModify must have shardkey",
"code" : 13343,
"ok" : 0
}
Can anyone explain to me why its saying this? or a solution for it? It seems to me that I'm doing everything that I need to.