Skip to content

Does upsert() work? #3

Description

@chmac

Reading the code here and seeing this:

        arr._id = arr.id + '';
        if(Wordpress.findOne({_id : arr.id + ""})){
            Wordpress.upsert(arr._id,arr)
        }else{
            Wordpress.insert(arr);
        }

Why do the findOne() and then .upsert() instead of just calling .upsert() directly?

The second parameter to .upsert() should be a Mongo modifier rather than an actual object. I'd guess that the code above doesn't really upsert() a document. It probably needs to be refactored to Wordpress.upsert(arr._id,{$set: arr}) for the .upsert() to succeed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions