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

How to use findOneAndUpdate with option upsert : true ? #214

Open
bv99 opened this issue Apr 14, 2019 · 0 comments
Open

How to use findOneAndUpdate with option upsert : true ? #214

bv99 opened this issue Apr 14, 2019 · 0 comments

Comments

@bv99
Copy link

bv99 commented Apr 14, 2019

So I want to save document with insert or update if exist, and figured out that findOneAndUpdate with opt {upsert:true} maybe could, but it encounter error when save(). How is proper use of this method? here is my code :

Mdel.upsert = async (where, data, cb) => {
		const start = new Date();
		const existdt = await Mdel.findOneAndUpdate(where, data, {
			upsert: true
		}).find();
		console.log('exisdata', existdt);
		await existdt.save();
		console.log('speed of upsert', new Date() - start);
		cb(existdt);
	};

and this is the error msg:

(node:21468) UnhandledPromiseRejectionWarning: TypeError: existdt.save is not a function
warning.js:18
at Function.Mdel.upsert (D:\app\botkorter\src\dbase.js:46:17)

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

1 participant