Skip to content

Instantly share code, notes, and snippets.

View AmitDJagtap's full-sized avatar
💭
rabbitmq this and rmq that

AmitDJagtap

💭
rabbitmq this and rmq that
View GitHub Profile
{
"name": "guardutyalert",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "damitj",
"license": "ISC",
{
"version": "0",
"id": "c8c4daa7-a20c-2f03-0070-b7393dd542ad",
"detail-type": "GuardDuty Finding",
"source": "aws.guardduty",
"account": "123456789012",
"time": "1970-01-01T00:00:00Z",
"region": "us-east-1",
"resources": [],
"detail": {
exports.handler = async(event) => {
var Slack = require('slack-node');
var slack = new Slack();
var webhookUri = process.env.SLACK_HOOK ? process.env.SLACK_HOOK : "https://hooks.slack.com/services/your/slack/hook";
slack.setWebhook(webhookUri);
console.log(event.region);
console.log(event.detail.severity);
console.log(event.detail.service.additionalInfo);
db.reviews.createIndex(
{
subject: "text",
comments: "text"
}
)
{
_id: 1,
item: "abc",
stock: [
{ size: "S", color: "red", quantity: 25
},
{ size: "S", color: "blue", quantity: 10
},
{ size: "M", color: "blue", quantity: 50
}
executionStats: {
"executionSuccess": true,
"nReturned": 3,
"executionTimeMillis": 0,
"totalKeysExamined": 3,
"totalDocsExamined": 3,
"executionStages": {}
}
>> db.findOne(id : xyz, Person).then((data) => {
// data = Hydrate(data);
data.name = 'new name';
data.title = 'Mrs';
db.save(data, Person).then((result) => {
resolve(result);
});
});
>> db.updateFields(Person, { query: { id: data.id }, fields: { $set: { name: 'new Name', title: 'Mrs' } } }
{ _id: ObjectId(), a: 1, b: "ab" }
{ _id: ObjectId(), a: 2, b: "cd" }
{ _id: ObjectId(), a: 3, b: "ef" }
{ _id: ObjectId(), a: 4, b: "jk" }
{ _id: ObjectId(), a: 5, b: "lm" }
{ _id: ObjectId(), a: 6, b: "no" }
{ _id: ObjectId(), a: 7, b: "pq" }
{ _id: ObjectId(), a: 8, b: "rs" }
{ _id: ObjectId(), a: 9, b: "tv" }
{ _id: ObjectId(), a: 1, b: "ab" }
{ _id: ObjectId(), a: 1, b: "cd" }
{ _id: ObjectId(), a: 1, b: "ef" }
{ _id: ObjectId(), a: 2, b: "jk" }
{ _id: ObjectId(), a: 2, b: "lm" }
{ _id: ObjectId(), a: 2, b: "no" }
{ _id: ObjectId(), a: 3, b: "pq" }
{ _id: ObjectId(), a: 3, b: "rs" }
{ _id: ObjectId(), a: 3, b: "tv" }
@AmitDJagtap
AmitDJagtap / Example3.js
Created November 2, 2019 08:42
Denormalizing One-to-N relationships
db.products.findOne()
{
name : 'left-handed smoke shifter',
manufacturer : 'Acme Corp',
catalog_number: 1234,
parts : [
{ id : ObjectID('AAAA'), name : '#4 grommet' }, // Part name is denormalised
{ id: ObjectID('F17C'), name : 'fan blade assembly' },
{ id: ObjectID('D2AA'), name : 'power switch' },
// etc