Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Update data without using find #170

Open
Signorini opened this issue Mar 22, 2017 · 1 comment
Open

Update data without using find #170

Signorini opened this issue Mar 22, 2017 · 1 comment

Comments

@Signorini
Copy link

Where way to make update document without using find?

I try to

let post = {_id: "fsdfsdasasd", changeme: true}

new Post(post).save()

//or

new Post(post).update()

but dont change

@tiagobnobrega
Copy link

tiagobnobrega commented Jul 22, 2017

Hi Signorini,

I was facing the same problem. I found out that, in my case, all I needed to do was transform the "_id" String representation into a actual ObjectId object.
Try this instead:

//import from native driver
const ObjectID = require('mongodb').ObjectID;

//will insert or update
let post = {_id: ObjectID("fsdfsdasasd"), changeme: true}
new Post(post).save()

//... Other stuff happening

//will update
let postAgain = {_id: ObjectID("fsdfsdasasd"), changeme: false}
new Post(postAgain ).save()

By the way... not tested ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants