Mongoose CRUD methods

mongoose of CRUD

-C creat:

Model objects .create (document object, the callback function)

Model objects .create (document object)

-R Read:

Model object .find (query, [projection]) Note ⚠️: with or without data, returns an array

Model object .findOne (query, projection]) Note ⚠️: find returns an object, returns an array not found

-U update

Model object .updateOne (query, you want to update content, [configuration object])

Model object .updateMany (query, you want to update content, [configuration object])

Note ⚠️: update methods exist, but soon abandoned the query to match multiple time, still only a modification, the proposed updateOne

-D delete

Model object .deleteOne (query)

Model object .deleteMany (query)

Note ⚠️: no delete method, wrong return
all of the above, if you do not specify a callback function, the return value is a promise Object

Published 29 original articles · won praise 0 · Views 198

Guess you like

Origin blog.csdn.net/qq_41523392/article/details/103690777