Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

Can't update the collection #414

Closed Ziyad33 closed 4 years ago

Ziyad33 commented 4 years ago

When I try to update the collection with the following code:

Drawings.update({_id: this._id}, {$push: {"votedUsers": Meteor.userId()}}, function(error, doc) {
            if(error){
                console.log(error);
            } else {
                console.log("Success");
            }
        });

I get the following error printed to the console:

errorClass {isClientSafe: true, error: 409, reason: "MongoError: Updating the path 'votedUsers' would create a conflict at 'votedUsers'", details: undefined, message: "MongoError: Updating the path 'votedUsers' would create a conflict at 'votedUsers' [409]", …} details: undefined error: 409 errorType: "Meteor.Error" isClientSafe: true message: "MongoError: Updating the path 'votedUsers' would create a conflict at 'votedUsers' [409]" reason: "MongoError: Updating the path 'votedUsers' would create a conflict at 'votedUsers'" stack: "Error: MongoError: Updating the path 'votedUsers' would create a conflict at 'votedUsers' [409]↵ at Connection._livedata_result (http://localhost:3000/packages/ddp-client.js?hash=5333e09ab08c9651b0cc016f95813ab4ce075f37:1796:23)↵ at Connection.onMessage (http://localhost:3000/packages/ddp-client.js?hash=5333e09ab08c9651b0cc016f95813ab4ce075f37:1962:12)↵ at http://localhost:3000/packages/socket-stream-client.js?hash=464d94df61b1613292cd125d83167741f86dc617:216:11↵ at Array.forEach ()↵ at ClientStream.forEachCallback (http://localhost:3000/packages/socket-stream-client.js?hash=464d94df61b1613292cd125d83167741f86dc617:297:31)↵ at SockJS.socket.onmessage (http://localhost:3000/packages/socket-stream-client.js?hash=464d94df61b1613292cd125d83167741f86dc617:215:14)↵ at SockJS.REventTarget.dispatchEvent (http://localhost:3000/packages/socket-stream-client.js?hash=464d94df61b1613292cd125d83167741f86dc617:545:22)↵ at SockJS._dispatchMessage (http://localhost:3000/packages/socket-stream-client.js?hash=464d94df61b1613292cd125d83167741f86dc617:1724:10)↵ at SockJS._didMessage (http://localhost:3000/packages/socket-stream-client.js?hash=464d94df61b1613292cd125d83167741f86dc617:1790:16)↵ at WebSocket.that.ws.onmessage (http://localhost:3000/packages/socket-stream-client.js?hash=464d94df61b1613292cd125d83167741f86dc617:1948:15)" proto: Error clone: ƒ () constructor: ƒ (/arguments/) proto: Object

The shorter version of the error is below:

update failed: MongoError: Updating the path 'votedUsers' would create a conflict at 'votedUsers'

What is causing the issue?

harryadel commented 4 years ago

Would you please share the schema attached to that collection? More preferably, it'd be nice if you create a sample app where we can replicate the issue.

coagmano commented 4 years ago

Have you got any autovalues set?

And have you tried it with bypassCollection2 to confirm that it's a collection2 issue?

harryadel commented 4 years ago

Closing. If anyone is still having this issue, please open a new PR with a test that replicates the issue.