app.post('/collect', (req, res) => { console.log(req.body); const client = new MongoClient(process.env.MONGO_URL); client.connect((err) => { const db = client.db(); const collection = db.collection('events'); collection.insertOne({ timestamp: new Date(), ...req.body }, ((err, result) => { client.close(); res.send('ok'); })); }); });
async function insertOne(collectionname, json){ const client = new MongoClient(url, {useUnifiedTopology: true}); await client.connect(); const col = client.db("spider").collection(collectionname); const result = await col.insertOne(json); client.close(); return result; }
static async addEvent() { const client = await mongoClientPromise; const db = client.db(dbName); const collection = db.collection(this.collectionName); await collection.insertOne({ createdAt: new Date(), message: randomstring.generate({length: 1000}), }); }
insertReview(review){ try{ this.reviews.insertOne(review); } catch(err){ console.error(err); } }
/** * Inserts a record into the collection * * @param {string} collection * @param {object} payload */ async insert(collection, payload) { let store = this.db.collection(collection); let result = await store.insertOne(payload); return result.ops[0]; }
function InsertDB(table,model) { return new Promise(function(resolve,reject){ if (client.isConnected()) { client.db(dbName).collection(table).insertOne(model).then(function(res){ resolve(res); }).catch(function(err){ reject(err); }); }else{ reject("Not Connected!"); } }); }
// Used to both create and update events. NOTE doUpsert=true is only used by demoData loading script createOrUpdateEvent(event, doUpsert) { if (event._id) { return this.db.collection(this.EVENT_COLLECTION).updateOne({_id: event._id, type: event.type}, {$set: event}, {upsert: doUpsert}); } else { // Create a random short-code style id for new events // IMPORTANT! // We have to create our own id as a string, because Azure Functions can't handle MongoDB self generated ids event._id = utils.makeId(5); return this.db.collection(this.EVENT_COLLECTION).insertOne(event); } }
const addNewTask = async (task) => { const db = await connectDB(); const collection = db.collection('tasks'); await collection.insertOne(task); }
createFeedback(feedback) { // IMPORTANT! // We have to create our own id as a string, because Azure Functions can't handle MongoDB self generated idss feedback._id = utils.makeId(12); return this.db.collection(this.FEEDBACK_COLLECTION).insertOne(feedback) }
client.connect(err => { const collection = client.db("noahdb").collection("questions"); var myobj = { name: "Company Inc", address: "Highway 40" }; collection.insertOne(myobj, function(err, res) { if (err) throw err; console.log("1 document inserted"); }); client.close(); });
insertPlayer(player){ try{ this.players.insertOne(player); } catch(err){ console.error(err); } }
insertModerationEntry(param, entry, options){ try{ this.moderationLog.insertOne(param,entry,options); }catch(err){ console.error(err); } }
insertMatchDate(match){ try{ this.matchDates.insertOne(match); } catch(err){ console.error(err); } }
/* Accouncements */ insertAnnouncement(param, announcement, options){ try{ this.announcements.insertOne(param,announcement,options); }catch(err){ console.error(err); } }
insertClan(clan){ try{ this.clans.insertOne(clan); } catch(err){ console.error(err); } }