Table of Content
AWS-SDK JS
- https://stackoverflow.com/questions/26726862/how-to-determine-if-object-exists-aws-s3-node-js-sdk
// Using callbacks
s3.headObject(params, function(err, metadata) {
if (err && err.code === "NotFound") {
// Handle no object on cloud here
} else {
s3.getSignedUrl("getObject", params, callback);
}
});
// Using async/await (untested)
try {
const headCode = await s3.headObject(params).promise();
const signedUrl = await s3.getSignedUrl("getObject", params).promise();
// Do something with signedUrl
} catch (headErr) {
if (headErr.code === "NotFound") {
// Handle no object on cloud here
}
}
Mongodb $in
- https://stackoverflow.com/questions/8303900/mongodb-mongoose-findmany-find-all-documents-with-ids-listed-in-array
model.find(
{
_id: {
$in: [
mongoose.Types.ObjectId("4ed3ede8844f0f351100000c"),
mongoose.Types.ObjectId("4ed3f117a844e0471100000d"),
mongoose.Types.ObjectId("4ed3f18132f50c491100000e")
]
}
},
function(err, docs) {
console.log(docs);
}
);
Today I Learned