Skip to content

Does upsert() work? #3

@chmac

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.

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