You likely have one or more docs with a created_at
value that's not a BSON Date
and you'll need to fix that by converting those values to Date
or removing them.
You can find those docs with a $not
query that uses the $type
operator like:
db.snippets.find({created_at: {$not: {$type: 9}}})
If the created_at
values are date strings, you can find the docs that need updating and then update them in the shell using code like:
db.snippets.find({created_at: {$not: {$type: 9}}}).forEach(function(doc) {
// Convert created_at to a Date
doc.created_at = new Date(doc.created_at);
db.snippets.save(doc);
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…