Internal Server Error while making $pop from array

Hello,

I have my schema as below:
Const Game = new SimpleSchema({
moves:[String]
});

and using above I have my array in mongodb as:

{
“moves”: [
“e4”,
“y6”,
“f2”
]
}

Now I want to remove last element from above ‘moves’ array so I used:

GameCollection.update({ _id: Id }, { $pop: { moves: 1 } });

but, I’m getting an error with message: Internal Server Error(500) with an exception message like:
Exception while invoking method ‘execute-game-action’ { MongoError: Expected a number in: moves: “1”

Please guide.

Don’t use SimpleSchema.

Hello,
Thanks for your reply. Actually, according to our requirement, I have to use schema, how can I define collection if I don’t use simpleschema. Any other alternative way with using schema?

You can use this to bypass collection2.

GameCollection.update({ _id: Id }, { $pop: { moves: 1 } }, { bypassCollection2: true });

Thank you so much. bypassCollection2 worked.

Why? It’s negligent to give advice such as this without a proper explanation.

Simple-Schema is a fantastic way to ensure data security and integrity.

This looks to possibly be a bug and I would suggest reporting it on GitHub accordingly.

1 Like