I am trying to upsert
a dataset to a Mongo collection.
When I run the below code, I am getting an error: MongoError: The dollar ($) prefixed field '$push' in '$push' is not valid for storage.
I put this together based on the docs: https://docs.mongodb.org/getting-started/node/update/#update-multiple-documents
Versions: MongoDB (windows) = 3.2.0; mongodb (npm package) = 2.1.4
var query = {
county: aCountyName,
state: aStateName
}
var params = {
'$set': {
county: 'Boone',
state: 'MO',
'$push': {
zips: {
'$each': [ '65203' ]
}
}
}
}
(could also be)
var params = {
'$set': {
county: 'Pierce',
state: 'WA',
'$push': {
zips: {
'$each': [ '98499', '98499' ]
}
}
}
}
db.collection(collectionName).updateMany(query, params, {'upsert': true},
function(err, results) {
callback();
}
);
I don't think $push
is valid within a $set
. Instead try adding it as another parameter, e.g.:
var params = {
'$set': {
county: 'Pierce',
state: 'WA'
},
'$push': {
zips: {
'$each': ['98499',
'98499']
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With