When I try to make a save function, then it goes an error.
ie. I tried db.collection.save()
my db is test and my collection name is myCol
test> db.myCol.find()
[
{
_id: ObjectId("62dd5dfd976a6f6126179768"),
name: 'J',
totVal: 5,
values: [ 'Hi', 'Hello', 'How' ],
valMin: 15
},
{
_id: ObjectId("62dd738a976a6f6126179769"),
name: 'K',
values: [ 'Hi', 'Hello', 'How' ],
totVal: 5,
valMin: 15
}
]
test> db.myCol.save({"_id": ObjectId(62dd738a976a6f6126179769),"name":"New Element"})
Uncaught:
SyntaxError: Identifier directly after number. (1:33)
> 1 | db.myCol.save({"_id": ObjectId(62dd738a976a6f6126179769),"name":"New Element"})
| ^
2 |
test>
tried this tooo
test> db.myCol.save({"_id": ObjectId("62dd738a976a6f6126179769"),"name":"New Element"})
TypeError: db.myCol.save is not a function
test>
2
Answers
It's done using this: Beacause- save is depricated and use replaceOne() instead of save().
Ensure that your
myCol
schema defines_id
: