Write a service usingnode
to provide an interface for the caller to encapsulate the parameters after passing in the parameters, andinsert
a record inmongo
, now it is found that some fields cannot be updated. The code is similar to the following
const db = mongodb.collection('collection_name'); let data = { a: 'value1', b: 'value2', c: 'value3' }; db.insert(data);
For example, thea
andb
fields indata
can be updated successfully, but thec
field is not inserted. At first I thought it was because themongodb
package used was out of date. Now I have updated to the latest version2.2.26
and the version still cannot be updated. Later, thefindOneAndUpdate
command was used instead, and the updated document was returned. The returned result had ac
value, but there was still noc
field inmongo
value. Ask God for answers! ! !
Try changing the save method without passing the _id value.
I simply tried it according to your statement, but I didn’t find what you said.
Software information: Database MongoDB 3.4 + driver mongodb 2.2.26
For reference.
Love MongoDB! Have fun!